Class: Expressive::Scope
- Inherits:
-
Object
- Object
- Expressive::Scope
- Defined in:
- lib/scope.rb
Direct Known Subclasses
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #define(name, &block) ⇒ Object
-
#initialize(parent = {}) ⇒ Scope
constructor
A new instance of Scope.
- #merge(scope) ⇒ Object
- #override_scope(scope) ⇒ Object
- #retrieve_scope ⇒ Object
- #syntax(name, &block) ⇒ Object
Constructor Details
#initialize(parent = {}) ⇒ Scope
Returns a new instance of Scope.
3 4 5 6 |
# File 'lib/scope.rb', line 3 def initialize(parent = {}) @parent = parent @symbols = {} end |
Instance Method Details
#[](name) ⇒ Object
8 9 10 |
# File 'lib/scope.rb', line 8 def [](name) @symbols[name] || @parent[name] end |
#[]=(name, value) ⇒ Object
12 13 14 |
# File 'lib/scope.rb', line 12 def []=(name, value) @symbols[name] = value end |
#define(name, &block) ⇒ Object
29 30 31 |
# File 'lib/scope.rb', line 29 def define(name, &block) self[name] = Function.new(&block) end |
#merge(scope) ⇒ Object
16 17 18 |
# File 'lib/scope.rb', line 16 def merge(scope) @symbols.merge!(scope) end |
#override_scope(scope) ⇒ Object
20 21 22 23 |
# File 'lib/scope.rb', line 20 def override_scope(scope) scope.merge!(@symbols) @symbols = scope end |
#retrieve_scope ⇒ Object
25 26 27 |
# File 'lib/scope.rb', line 25 def retrieve_scope @symbols end |