Class: Philiprehberger::Template::Context
- Inherits:
-
Object
- Object
- Philiprehberger::Template::Context
- Defined in:
- lib/philiprehberger/template/context.rb
Instance Method Summary collapse
- #defined?(name) ⇒ Boolean
-
#initialize(variables = {}) ⇒ Context
constructor
A new instance of Context.
- #lookup(name) ⇒ Object
- #pop ⇒ Object
- #push(scope) ⇒ Object
Constructor Details
#initialize(variables = {}) ⇒ Context
Returns a new instance of Context.
6 7 8 |
# File 'lib/philiprehberger/template/context.rb', line 6 def initialize(variables = {}) @stack = [normalize(variables)] end |
Instance Method Details
#defined?(name) ⇒ Boolean
18 19 20 21 22 23 24 |
# File 'lib/philiprehberger/template/context.rb', line 18 def defined?(name) key = name.to_sym @stack.reverse_each do |scope| return true if scope.key?(key) end false end |
#lookup(name) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/philiprehberger/template/context.rb', line 10 def lookup(name) key = name.to_sym @stack.reverse_each do |scope| return scope[key] if scope.key?(key) end nil end |
#pop ⇒ Object
30 31 32 |
# File 'lib/philiprehberger/template/context.rb', line 30 def pop @stack.pop if @stack.size > 1 end |
#push(scope) ⇒ Object
26 27 28 |
# File 'lib/philiprehberger/template/context.rb', line 26 def push(scope) @stack.push(normalize(scope)) end |