Ruby: Deep merge yaml files without overwriting parent
<p>I have two YAML files from i18n, where certain keys in the first file are overwritten in the second file. I want to merge this two YAML files into one, so I read the two files into a hash, and tried to merge them:</p>

<pre><code>a = {
  en: {
    test: {
      bar: "bar",
      foo: "foo"
    }
  }
}

b = {
  en: {
    test: {
      bar: "hello world"
    }
  }
}

a.merge!(b)
puts a
# =&gt; {:de=&gt;{:test=&gt;{:bar=&gt;"hello world"}}}
#
# but should return
# =&gt; {:de=&gt;{:test=&gt;{:bar=&gt;"hello world", :foo =&gt; "foo"}}}
</code></pre>

<p>The problem is, that the parent key <code>test</code> gets completely overwritten. Is there an easy way to only overwrite <code>bar</code> but keep the key/value from <code>foo</code>?</p>

<p>(this are just examples, the nesting is deeper for some keys, 4 or 5 levels deep)</p>