Sha256: a6dd270faa632939ffe04dd1715a8a13eb06d3c54c97f28020a270fcab920745

Contents?: true

Size: 376 Bytes

Versions: 1

Compression:

Stored size: 376 Bytes

Contents

class Hash

  def deep_merge(other_hash, &block)
    dup.deep_merge!(other_hash, &block)
  end

  def deep_merge!(other_hash, &block)
    other_hash.each_pair do |k,v|
      tv = self[k]
      if tv.is_a?(Hash) && v.is_a?(Hash)
        self[k] = tv.deep_merge(v, &block)
      else
        self[k] = block && tv ? block.call(k, tv, v) : v
      end
    end
    self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
happy_support-1.0.0 lib/happy_support/core_ext/hash/deep_merge.rb