Sha256: 5c54ec4ba90581e4649dd8c23392529c082489b55af2f68a36ee29c452766cf9
Contents?: true
Size: 629 Bytes
Versions: 2
Compression:
Stored size: 629 Bytes
Contents
class Hash # Apply a block to hash, and recursively apply that block # to each subhash. # # h = {:a=>1, :b=>{:b1=>1, :b2=>2}} # h.recursively{|h| h.rekey(&:to_s) } # => {"a"=>1, "b"=>{"b1"=>1, "b2"=>2}} # def recursively(&block) warn "Use #recusive instead of #recursively for future versions" h = inject({}) do |hash, (key, value)| if value.is_a?(Hash) hash[key] = value.recursively(&block) else hash[key] = value end hash end yield h end # In place form of #recursively. def recursively!(&block) replace(recursively(&block)) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
facets-2.8.4 | lib/core/facets/hash/recursively.rb |
facets-2.8.3 | lib/core/facets/hash/recursively.rb |