Class: Plasma::Interpreter::Env
- Defined in:
- lib/plasma/interpreter/plasma_grammarnode.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #bind!(key, value) ⇒ Object
-
#initialize(init = {}, default = nil) ⇒ Env
constructor
A new instance of Env.
- #merge!(hash) ⇒ Object
- #release! ⇒ Object
- #resolve(key) ⇒ Object
- #scope(inner = {}) ⇒ Object
- #scope!(inner = {}) ⇒ Object
- #to_plasma ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(init = {}, default = nil) ⇒ Env
Returns a new instance of Env.
7 8 9 10 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 7 def initialize(init={}, default=nil) @state = [init] @default = default end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
5 6 7 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 5 def default @default end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 4 def state @state end |
Instance Method Details
#bind!(key, value) ⇒ Object
20 21 22 23 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 20 def bind!(key, value) @state.last[key] = value self end |
#merge!(hash) ⇒ Object
25 26 27 28 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 25 def merge!(hash) @state.last.merge!(hash) self end |
#release! ⇒ Object
35 36 37 38 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 35 def release!() @state.pop self end |
#resolve(key) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 54 def resolve(key) @state.reverse_each do |layer| return layer[key] if layer.include?(key) end # nothing to find return default end |
#scope(inner = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 40 def scope(inner={}) self.scope!(inner) begin value = yield self self.release! return value rescue => detail self.release! detail end end |
#scope!(inner = {}) ⇒ Object
30 31 32 33 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 30 def scope!(inner={}) @state.push(inner) self end |
#to_plasma ⇒ Object
16 17 18 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 16 def to_plasma @state.to_plasma end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 12 def to_s @state.map {|s| s.inspect}.join("\n") end |