Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/capgun/core_ext/hash.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(hash) ⇒ Hash

Merges self with another hash, recursively

Parameters:

  • hash (Hash)

    The hash to merge

Returns:



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/capgun/core_ext/hash.rb', line 7

def deep_merge(hash)
  target = self.dup
  hash.keys.each do |key|
    if hash[key].is_a?(Hash) && self[key].is_a?(Hash)
      target[key] = target[key].deep_merge(hash[key])
      next
    end
    target[key] = hash[key]
  end
  target
end