Class: StackableArray
- Inherits:
-
Array
- Object
- Array
- StackableArray
- Defined in:
- lib/ext/stackable_array.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_array.rb', line 2 def current_key @current_key end |
#parent ⇒ Object
Returns the value of attribute parent.
2 3 4 |
# File 'lib/ext/stackable_array.rb', line 2 def parent @parent end |
Instance Method Details
#child(key) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/ext/stackable_array.rb', line 4 def child(key) hash = StackableHash.new hash[key] = StackableHash.new new_target = self.current new_target.merge!(hash) new_target.current_key = key new_target.parent = self new_target end |
#current ⇒ Object
31 32 33 |
# File 'lib/ext/stackable_array.rb', line 31 def current self.current_key ? self.last[current_key] : self.last end |
#current=(value) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/ext/stackable_array.rb', line 23 def current=(value) if self.current.is_a?(Hash) self.last[current_key] = value else self << value end end |
#merge!(hash) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/ext/stackable_array.rb', line 15 def merge!(hash) if self.last.is_a?(Hash) && !self.last.key?(hash.keys.first) self.last.merge!(hash) else self << hash end end |