Class: Platform::IEL::EvaluationContext
- Inherits:
-
Object
- Object
- Platform::IEL::EvaluationContext
- Defined in:
- lib/introhive_expression_language/iel/evaluation_context.rb
Instance Attribute Summary collapse
-
#enclosing_context ⇒ Object
readonly
Returns the value of attribute enclosing_context.
Instance Method Summary collapse
- #[](symbol) ⇒ Object
- #[]=(symbol, symbol_detail) ⇒ Object
- #constant_name?(symbol) ⇒ Boolean
-
#initialize(enclosing_context = nil) ⇒ EvaluationContext
constructor
A new instance of EvaluationContext.
-
#root_context ⇒ Object
Find and return the root context by following enclosing contexts.
Constructor Details
#initialize(enclosing_context = nil) ⇒ EvaluationContext
Returns a new instance of EvaluationContext.
6 7 8 9 |
# File 'lib/introhive_expression_language/iel/evaluation_context.rb', line 6 def initialize(enclosing_context = nil) @enclosing_context = enclosing_context @symbols = {} end |
Instance Attribute Details
#enclosing_context ⇒ Object (readonly)
Returns the value of attribute enclosing_context.
4 5 6 |
# File 'lib/introhive_expression_language/iel/evaluation_context.rb', line 4 def enclosing_context @enclosing_context end |
Instance Method Details
#[](symbol) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/introhive_expression_language/iel/evaluation_context.rb', line 11 def [](symbol) out = @symbols[symbol] return out if out.present? return @enclosing_context[symbol] if @enclosing_context nil end |
#[]=(symbol, symbol_detail) ⇒ Object
18 19 20 21 22 |
# File 'lib/introhive_expression_language/iel/evaluation_context.rb', line 18 def []=(symbol, symbol_detail) raise StandardError, "Cannot write symbol '#{symbol}' value '#{symbol_detail.inspect}' as it is not of type Platform::IEL::SexpParser::Node" unless symbol_detail.is_a?(SexpParser::Node) raise StandardError, "Cannot redefine constant symbol '#{symbol}' value '#{symbol_detail.inspect}'" if constant_name?(symbol) && self[symbol] @symbols[symbol] = symbol_detail end |
#constant_name?(symbol) ⇒ Boolean
24 25 26 |
# File 'lib/introhive_expression_language/iel/evaluation_context.rb', line 24 def constant_name?(symbol) symbol.start_with?('C_') end |
#root_context ⇒ Object
Find and return the root context by following enclosing contexts.
29 30 31 32 |
# File 'lib/introhive_expression_language/iel/evaluation_context.rb', line 29 def root_context return enclosing_context.root_context if enclosing_context self end |