Class: StackableHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/ext/stackable_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#stackable

Instance Attribute Details

#current_keyObject

Returns the value of attribute current_key.



8
9
10
# File 'lib/ext/stackable_hash.rb', line 8

def current_key
  @current_key
end

#parentObject

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

#currentObject



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