Sha256: 0194bb4aa222e48704202d3d199a0a6f49277326961e3416b735b18df8b4492c

Contents?: true

Size: 650 Bytes

Versions: 13

Compression:

Stored size: 650 Bytes

Contents

class Hash

  # Same as Hash#merge but recursively merges sub-hashes.

  def recursive_merge(other)
    hash = self.dup
    other.each do |key, value|
      myval = self[key]
      if value.is_a?(Hash) && myval.is_a?(Hash)
        hash[key] = myval.recursive_merge(value)
      else
        hash[key] = value
      end
    end
    hash
  end

  # Same as Hash#merge! but recursively merges sub-hashes.

  def recursive_merge!(other)
    other.each do |key, value|
      myval = self[key]
      if value.is_a?(Hash) && myval.is_a?(Hash)
        myval.recursive_merge!(value)
      else
        self[key] = value
      end
    end
    self
  end

end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
facets-2.8.2 lib/core/facets/hash/recursive_merge.rb
facets-2.8.1 lib/core/facets/hash/recursive_merge.rb
facets-2.8.0 lib/core/facets/hash/recursive_merge.rb
facets-2.7.0 lib/core/facets/hash/recursive_merge.rb
facets-2.6.0 lib/core/facets/hash/recursive_merge.rb
facets-2.4.2 lib/core/facets/hash/recursive_merge.rb
facets-2.4.3 lib/core/facets/hash/recursive_merge.rb
facets-2.4.4 lib/core/facets/hash/recursive_merge.rb
facets-2.4.5 lib/core/facets/hash/recursive_merge.rb
facets-2.5.1 lib/core/facets/hash/recursive_merge.rb
facets-2.5.0 lib/core/facets/hash/recursive_merge.rb
facets-2.5.2 lib/core/facets/hash/recursive_merge.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/hash/recursive_merge.rb