Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/yamlstrings/utils.rb

Instance Method Summary collapse

Instance Method Details

#hflatten(path = []) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/yamlstrings/utils.rb', line 4

def hflatten(path=[])
  self.inject({}) do |a,(k,v)|
    if v.is_a? Hash
      # Recurse
      a.merge(v.hflatten(path.dup << k))
    else
      # Base case
      a[(path.dup << k).join('.')] = v; a
    end
  end
end