Sha256: 6c9b4e0e813ede58929346dbd7addf5ca5f37c401ff6220945dbe6e27d068ab9
Contents?: true
Size: 854 Bytes
Versions: 5
Compression:
Stored size: 854 Bytes
Contents
class Hash # Merges self with another hash, recursively. # # This code was lovingly stolen from some random gem: # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html # # Thanks to whoever made it. def deep_merge(hash) target = dup hash.keys.each do |key| if hash[key].is_a? Hash and self[key].is_a? Hash target[key] = target[key].deep_merge(hash[key]) next end target[key] = hash[key] end target end # From: http://www.gemtacular.com/gemdocs/cerberus-0.2.2/doc/classes/Hash.html # File lib/cerberus/utils.rb, line 42 def deep_merge!(second) second.each_pair do |k,v| if self[k].is_a?(Hash) and second[k].is_a?(Hash) self[k].deep_merge!(second[k]) else self[k] = second[k] end end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
rego-ruby-ext-0.0.6 | lib/hash-ext.rb |
rego-ruby-ext-0.0.5 | lib/hash.rb |
rego-ruby-ext-0.0.4 | lib/hash.rb |
rego-ruby-ext-0.0.3 | lib/hash.rb |
rego-ruby-ext-0.0.2 | lib/hash.rb |