Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_deploy/hash_deep_merge.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(second) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/danarchy_deploy/hash_deep_merge.rb', line 2

def deep_merge(second)
  merger = proc do |key, v1, v2|
    Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2
  end

  self.merge(second.to_h, &merger)
end