Class: StackableHash
- Inherits:
-
Hash
- Object
- Hash
- StackableHash
- Defined in:
- lib/ext/stackable_hash.rb
Instance Attribute Summary collapse
-
#current_key ⇒ Object
Returns the value of attribute current_key.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
Instance Attribute Details
#current_key ⇒ Object
Returns the value of attribute current_key.
2 3 4 |
# File 'lib/ext/stackable_hash.rb', line 2 def current_key @current_key end |
#parent ⇒ Object
Returns the value of attribute parent.
2 3 4 |
# File 'lib/ext/stackable_hash.rb', line 2 def parent @parent end |
Instance Method Details
#<<(value) ⇒ Object
15 16 17 |
# File 'lib/ext/stackable_hash.rb', line 15 def <<(value) self[current_key] << value end |
#child(key) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/ext/stackable_hash.rb', line 4 def child(key) hash = StackableHash.new hash[key] = StackableHash.new new_target = self.current || self new_target.merge!(hash) new_target.current_key = key new_target.parent = self new_target end |
#current ⇒ Object
23 24 25 |
# File 'lib/ext/stackable_hash.rb', line 23 def current self[current_key] end |
#current=(value) ⇒ Object
19 20 21 |
# File 'lib/ext/stackable_hash.rb', line 19 def current=(value) self[current_key] = value end |