Class: Halunke::Interpreter::Context
- Inherits:
-
Object
- Object
- Halunke::Interpreter::Context
- Defined in:
- lib/halunke/interpreter.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #create_child ⇒ Object
-
#initialize(parent = nil) ⇒ Context
constructor
A new instance of Context.
- #key?(name) ⇒ Boolean
Constructor Details
#initialize(parent = nil) ⇒ Context
Returns a new instance of Context.
53 54 55 56 |
# File 'lib/halunke/interpreter.rb', line 53 def initialize(parent = nil) @parent = parent @context = {} end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
51 52 53 |
# File 'lib/halunke/interpreter.rb', line 51 def parent @parent end |
Instance Method Details
#[](name) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/halunke/interpreter.rb', line 63 def [](name) @context.fetch(name) rescue KeyError raise KeyError if @parent.nil? @parent[name] end |
#[]=(name, value) ⇒ Object
58 59 60 61 |
# File 'lib/halunke/interpreter.rb', line 58 def []=(name, value) raise FrozenError if key? name @context[name] = value end |
#create_child ⇒ Object
74 75 76 |
# File 'lib/halunke/interpreter.rb', line 74 def create_child Context.new(self) end |
#key?(name) ⇒ Boolean
70 71 72 |
# File 'lib/halunke/interpreter.rb', line 70 def key?(name) @context.key?(name) end |