Class: Chef::Mixin::DeepMerge

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/mixin/deep_merge.rb

Class Method Summary collapse

Class Method Details

.merge(first, second) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chef/mixin/deep_merge.rb', line 21

def self.merge(first, second)
  first = Mash.new(first).to_hash unless second.kind_of?(Mash)
  first = first.to_hash
  second = Mash.new(second).to_hash unless second.kind_of?(Mash)
  second = second.to_hash
  # Originally From: http://www.ruby-forum.com/topic/142809
  # Author: Stefan Rusterholz
  merger = proc do |key,v1,v2| 
      v1.respond_to?(:keys) && v2.respond_to?(:keys) ? v1.merge(v2, &merger) : v2 
    end

  Mash.new(first.merge(second, &merger))
end