tumblr/jetpants — pull request #10 by tbchrist (2013-02-21 19:58:21+00:00)
Title: Deep merge configs

Add a monkeypatch to Hash that enables deep merging, and call it on the configs. See a test script:

```
#!/opt/ruby-1.9.2/bin/ruby

class Hash
def deep_merge!(other_hash)
merge!(other_hash) do |key, oldval, newval|
(oldval.class == self.class && newval.class == oldval.class) ? oldval.deep_merge!(newval) : newval
end
end
end

obj1 = { 'one' => { 'foo' => { 'bar' => 'baz'}}, 'two' => 2, 'three' => [0,1,2], 'four' => [3,4,5], 'five' => {'foo' => 'bar'}}
obj2 = { 'one' => { 'foo' => { 'bar' => 'qux'}}, 'four' => [6,7,7], 'five' => 5, 'six' => 666}

puts "Original:"
puts obj1
puts "To Merge:"
puts obj2

obj1.deep_merge!(obj2)

puts "Merged:"
puts obj1
```

output:

```
[tchrist@dev-tchrist-941b2756.ewr01 jetpants]$ ./test.rb
Original:
{"one"=>{"foo"=>{"bar"=>"baz"}}, "two"=>2, "three"=>[0, 1, 2], "four"=>[3, 4, 5], "five"=>{"foo"=>"bar"}}
To Merge:
{"one"=>{"foo"=>{"bar"=>"qux"}}, "four"=>[6, 7, 7], "five"=>5, "six"=>666}
Merged:
{"one"=>{"foo"=>{"bar"=>"qux"}}, "two"=>2, "three"=>[0, 1, 2], "four"=>[6, 7, 7], "five"=>5, "six"=>666}
```