Class: Expressive::Scope
- Inherits:
-
Object
- Object
- Expressive::Scope
- Defined in:
- lib/scope.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#lookups ⇒ Object
readonly
Returns the value of attribute lookups.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #add_lookup_function(lookup_function_name, passed_in_options = {}, &func_proc) ⇒ Object
- #add_lookup_table(lookup_table_name, lookups) ⇒ Object
- #clear_lookup_tables ⇒ Object
- #define(name, &block) ⇒ Object
- #include?(name) ⇒ Boolean
-
#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
6 7 8 9 10 |
# File 'lib/scope.rb', line 6 def initialize(parent = {}) @parent = parent @symbols = {} @lookups = {} end |
Instance Attribute Details
#lookups ⇒ Object (readonly)
Returns the value of attribute lookups.
5 6 7 |
# File 'lib/scope.rb', line 5 def lookups @lookups end |
Instance Method Details
#[](name) ⇒ Object
29 30 31 |
# File 'lib/scope.rb', line 29 def [](name) @symbols[name] || @parent[name] end |
#[]=(name, value) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/scope.rb', line 33 def []=(name, value) if value if value.is_a?(ExtendedValue) @symbols[name] = value unless @symbols.include?(name) else current_value = @symbols[name] if current_value and current_value.is_a?(ExtendedValue) current_value.set(value) else @symbols[name] = value end end else @symbols[name] = value end end |
#add_lookup_function(lookup_function_name, passed_in_options = {}, &func_proc) ⇒ Object
17 18 19 |
# File 'lib/scope.rb', line 17 def add_lookup_function(lookup_function_name, = {}, &func_proc) @lookups[lookup_function_name] = [, func_proc] end |
#add_lookup_table(lookup_table_name, lookups) ⇒ Object
12 13 14 15 |
# File 'lib/scope.rb', line 12 def add_lookup_table(lookup_table_name, lookups) @lookups[lookup_table_name] = {} unless @lookups.include?(lookup_table_name) @lookups[lookup_table_name].merge!(lookups) end |
#clear_lookup_tables ⇒ Object
21 22 23 |
# File 'lib/scope.rb', line 21 def clear_lookup_tables @lookups.clear end |
#define(name, &block) ⇒ Object
63 64 65 |
# File 'lib/scope.rb', line 63 def define(name, &block) self[name] = Function.new(&block) end |
#include?(name) ⇒ Boolean
25 26 27 |
# File 'lib/scope.rb', line 25 def include?(name) @symbols.include?(name) or @lookups.include?(name) end |
#merge(scope) ⇒ Object
50 51 52 |
# File 'lib/scope.rb', line 50 def merge(scope) @symbols.merge!(scope) end |
#override_scope(scope) ⇒ Object
54 55 56 57 |
# File 'lib/scope.rb', line 54 def override_scope(scope) scope.merge!(@symbols) @symbols = scope end |
#retrieve_scope ⇒ Object
59 60 61 |
# File 'lib/scope.rb', line 59 def retrieve_scope @symbols end |
#syntax(name, &block) ⇒ Object
67 68 69 |
# File 'lib/scope.rb', line 67 def syntax(name, &block) self[name] = Syntax.new(&block) end |