Module: HashExt::Traverse

Defined in:
lib/hash_ext/traverse.rb

Class Method Summary collapse

Class Method Details

.traverse(hash, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/hash_ext/traverse.rb', line 3

def self.traverse(hash, &block)
  hash.inject({}) do |h,(k,v)|
    if Hash === v
      v = traverse(v,&block)
    end
    nk, nv = block.call(k,v)
    h[nk] = nv unless nk.nil?
    h
  end
end