class Hash # Returns a new hash created by traversing the hash and its subhashes, # executing the given block on the key and value. The block should # return a 2-element array of the form +[key, value]+. # # require 'facet/hash/traverse' # # h = { "A"=>"A", "B"=>"B" } # h.traverse { |k,v| [k.downcase, v] } # h #=> { "a"=>"A", "b"=>"B" } # def traverse(&b) inject({}) do |h,(k,v)| nk, nv = b[k,v] h[nk] = ( Hash === v ? v.traverse(&b) : nv ) h end end end