Class: Hyde::Util::Lookup
- Inherits:
-
Object
- Object
- Hyde::Util::Lookup
- Defined in:
- lib/hyde/util/lookup.rb
Overview
Value container with recursive lookup
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Class Method Summary collapse
-
.[](hash) ⇒ Object
Initialize a Lookup from Hash.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Get a value by key.
-
#[]=(key, value) ⇒ Object
Set a value by key.
-
#initialize(parent = nil, hash = {}) ⇒ Lookup
constructor
A new instance of Lookup.
Constructor Details
#initialize(parent = nil, hash = {}) ⇒ Lookup
Returns a new instance of Lookup.
9 10 11 12 |
# File 'lib/hyde/util/lookup.rb', line 9 def initialize(parent = nil, hash = {}) @parent = (parent or Hash.new(nil)) @storage = hash end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
34 35 36 |
# File 'lib/hyde/util/lookup.rb', line 34 def parent @parent end |
Class Method Details
Instance Method Details
#[](key) ⇒ Object?
Get a value by key
23 24 25 |
# File 'lib/hyde/util/lookup.rb', line 23 def [](key) @storage[key] or @parent[key] end |
#[]=(key, value) ⇒ Object
Set a value by key
30 31 32 |
# File 'lib/hyde/util/lookup.rb', line 30 def []=(key, value) @storage[key] = value end |