Sha256: 050226d9af3a4c5a824580b126cdca4fde9187b45b92b040ec99749733781b21
Contents?: true
Size: 1.36 KB
Versions: 84
Compression:
Stored size: 1.36 KB
Contents
# https://raw.github.com/Offirmo/hash-deep-merge/master/lib/hash_deep_merge.rb class Hash def deep_merge!(specialized_hash) internal_deep_merge!(self, specialized_hash) end def deep_merge(specialized_hash) internal_deep_merge!(Hash.new.replace(self), specialized_hash) end protected # better, recursive, preserving method # OK OK this is not the most efficient algorithm, # but at last it's *perfectly clear and understandable* # so fork and improve if you need 5% more speed, ok ? def internal_deep_merge!(source_hash, specialized_hash) #puts "starting deep merge..." specialized_hash.each_pair do |rkey, rval| #puts " potential replacing entry : " + rkey.inspect if source_hash.has_key?(rkey) then #puts " found potentially conflicting entry for #{rkey.inspect} : #{rval.inspect}, will merge :" if rval.is_a?(Hash) and source_hash[rkey].is_a?(Hash) then #puts " recursing..." internal_deep_merge!(source_hash[rkey], rval) elsif rval == source_hash[rkey] then #puts " same value, skipping." else #puts " replacing." source_hash[rkey] = rval end else #puts " found new entry #{rkey.inspect}, adding it..." source_hash[rkey] = rval end end #puts "deep merge done." source_hash end end
Version data entries
84 entries across 84 versions & 1 rubygems
Version | Path |
---|---|
riemann-babbler-0.9.2 | lib/deep_merge.rb |
riemann-babbler-0.9.1 | lib/deep_merge.rb |
riemann-babbler-0.9.0 | lib/deep_merge.rb |
riemann-babbler-0.8.9 | lib/deep_merge.rb |