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
Returns a new instance of Scope.
7 8 9 10 11 |
# File 'lib/scope.rb', line 7 def initialize(parent = {}) @parent = parent @symbols = {} @lookups = {} end |
Instance Attribute Details
#lookups ⇒ Object (readonly)
Returns the value of attribute lookups.
6 7 8 |
# File 'lib/scope.rb', line 6 def lookups @lookups end |
Instance Method Details
#[](name) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/scope.rb', line 30 def [](name) if @symbols[name].nil? @parent[name] else @symbols[name] end end |
#[]=(name, value) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/scope.rb', line 38 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
18 19 20 |
# File 'lib/scope.rb', line 18 def add_lookup_function(lookup_function_name, = {}, &func_proc) @lookups[lookup_function_name] = [, func_proc] end |
#add_lookup_table(lookup_table_name, lookups) ⇒ Object
13 14 15 16 |
# File 'lib/scope.rb', line 13 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
22 23 24 |
# File 'lib/scope.rb', line 22 def clear_lookup_tables @lookups.clear end |
#define(name, &block) ⇒ Object
68 69 70 |
# File 'lib/scope.rb', line 68 def define(name, &block) self[name] = Function.new(&block) end |
#include?(name) ⇒ Boolean
26 27 28 |
# File 'lib/scope.rb', line 26 def include?(name) @symbols.include?(name) or @lookups.include?(name) end |
#merge(scope) ⇒ Object
55 56 57 |
# File 'lib/scope.rb', line 55 def merge(scope) @symbols.merge!(scope) end |
#override_scope(scope) ⇒ Object
59 60 61 62 |
# File 'lib/scope.rb', line 59 def override_scope(scope) scope.merge!(@symbols) @symbols = scope end |
#retrieve_scope ⇒ Object
64 65 66 |
# File 'lib/scope.rb', line 64 def retrieve_scope @symbols end |