Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/layeredyamlconfig/hash_traverse.rb

Overview

adapted from Ruby Facets (github.com/rubyworks/facets) to support nested Array traversal we’re using the Ruby license, clause 2a by making LayeredYAMLConfig freely available

Instance Method Summary collapse

Instance Method Details

#traverse(&blk) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/layeredyamlconfig/hash_traverse.rb', line 5

def traverse(&blk)
    nh = {}
    inject(nh) do |h, (k, v)|
        case v
            when Hash
                v = v.traverse(&blk)
            when Array
                v = v.traverse(&blk)
        end
        nv = blk.call(v)
        h[k.to_sym] = nv
        h
    end
end