Class: Parslet::Scope::Binding

Inherits:
Object
  • Object
show all
Defined in:
lib/parslet/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Binding

Returns a new instance of Binding.



10
11
12
13
# File 'lib/parslet/scope.rb', line 10

def initialize(parent=nil)
  @parent = parent
  @hash = Hash.new
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



8
9
10
# File 'lib/parslet/scope.rb', line 8

def parent
  @parent
end

Instance Method Details

#[](k) ⇒ Object



15
16
17
18
19
# File 'lib/parslet/scope.rb', line 15

def [](k)
  @hash.has_key?(k) && @hash[k] ||
    parent && parent[k] or 
    raise NotFound
end

#[]=(k, v) ⇒ Object



20
21
22
# File 'lib/parslet/scope.rb', line 20

def []=(k,v)
  @hash.store(k,v)
end