Class: StackableHash
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
Methods inherited from Hash
Instance Attribute Details
#current_key ⇒ Object
Returns the value of attribute current_key.
8 9 10 |
# File 'lib/ext/stackable_hash.rb', line 8 def current_key @current_key end |
#parent ⇒ Object
Returns the value of attribute parent.
8 9 10 |
# File 'lib/ext/stackable_hash.rb', line 8 def parent @parent end |
Instance Method Details
#<<(value) ⇒ Object
19 20 21 |
# File 'lib/ext/stackable_hash.rb', line 19 def <<(value) self[current_key] << value end |
#child(key) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/ext/stackable_hash.rb', line 10 def child(key) hash = {key => StackableHash.new}.stackable new_target = self.current || self new_target.merge!(hash) new_target.current_key = key new_target.parent = self new_target end |
#current ⇒ Object
27 28 29 |
# File 'lib/ext/stackable_hash.rb', line 27 def current self[current_key] end |
#current=(value) ⇒ Object
23 24 25 |
# File 'lib/ext/stackable_hash.rb', line 23 def current=(value) self[current_key] = value end |