Class: Mullet::DefaultNestedScope
- Inherits:
-
Object
- Object
- Mullet::DefaultNestedScope
- Includes:
- Scope
- Defined in:
- lib/mullet/default_nested_scope.rb
Overview
Composite scope that combines scopes in nested scopes. Tries each scope in sequence until a value is successfully resolved.
Constant Summary
Constants included from Scope
Instance Method Summary collapse
-
#get_variable_value(name) ⇒ Object
Resolves variable name to value.
-
#initialize(*data_objects) ⇒ DefaultNestedScope
constructor
Constructor.
-
#pop_scope ⇒ Object
Removes innermost nested scope.
-
#push_scope(data) ⇒ Object
Adds new innermost nested scope.
Constructor Details
#initialize(*data_objects) ⇒ DefaultNestedScope
Constructor
14 15 16 17 |
# File 'lib/mullet/default_nested_scope.rb', line 14 def initialize(*data_objects) @scopes = [] data_objects.each {|data| push_scope(data) } end |
Instance Method Details
#get_variable_value(name) ⇒ Object
Resolves variable name to value.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mullet/default_nested_scope.rb', line 24 def get_variable_value(name) @scopes.reverse_each do |scope| value = scope.get_variable_value(name) if value != NOT_FOUND return value end end return NOT_FOUND end |
#pop_scope ⇒ Object
Removes innermost nested scope.
45 46 47 |
# File 'lib/mullet/default_nested_scope.rb', line 45 def pop_scope() @scopes.pop() end |
#push_scope(data) ⇒ Object
Adds new innermost nested scope.
39 40 41 42 |
# File 'lib/mullet/default_nested_scope.rb', line 39 def push_scope(data) @scopes.push( data.respond_to?(:get_variable_value) ? data : DefaultScope.new(data)) end |