Class: Hash

Inherits:
Object show all
Defined in:
lib/lore/bits.rb

Direct Known Subclasses

Lore::Attribute_Hash

Instance Method Summary collapse

Instance Method Details

#deep_merge!(second) ⇒ Object



25
26
27
28
# File 'lib/lore/bits.rb', line 25

def deep_merge!(second)
  merger = proc { |key,v1,v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
  self.merge!(second, &merger)
end

#keys_flat(keys_result = []) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/lore/bits.rb', line 43

def keys_flat(keys_result=[])
  keys.each { |k|
   keys_result << k
   child = self[k]
   child.keys_flat(keys_result) if (child && child.kind_of?(Hash))
  } 
  return keys_result
end

#merge_nested_hash!(nested_hash) ⇒ Object



39
40
41
# File 'lib/lore/bits.rb', line 39

def merge_nested_hash!(nested_hash)
  deep_merge!(nested_hash)
end

#nested_hash(array) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/lore/bits.rb', line 30

def nested_hash(array)
  node = self
  array.each do |i|
     node[i]=Hash.new if node[i].nil?
     node = node[i]
  end 
  self
end