Class: StackableHash

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_keyObject

Returns the value of attribute current_key.



2
3
4
# File 'lib/ext/stackable_hash.rb', line 2

def current_key
  @current_key
end

#parentObject

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

#currentObject



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