title: Merge same named arrays in ruby hashes
body: <p>I'd like to take two hashes of a form like these:</p>
  
  <pre><code>hash_1 = {:a=&gt;{:b=&gt;3, :c=&gt;{:stuff1=&gt;[{:d=&gt;1, :e=&gt;2}, {:d=&gt;4, :e=&gt;2}], :stuff2=&gt;[{:f=&gt;33, :g=&gt;44}, {:f=&gt;55, :g=&gt;66}], :h=&gt;4}}}
  
  hash_2 = {:a=&gt;{:b=&gt;3, :c=&gt;{:stuff1=&gt;[{:d=&gt;8, :e=&gt;5}, {:d=&gt;7, :e=&gt;5}], :stuff2=&gt;[{:f=&gt;45, :g=&gt;89}, {:f=&gt;78, :g=&gt;67}], :h=&gt;4}}}
  </code></pre>
  
  <p>And get this back (note <code>:stuff1</code> and <code>:stuff2</code> are added together):</p>
  
  <pre><code>result = {:a=&gt;{:b=&gt;3, :c=&gt;{:stuff1=&gt;[{:d=&gt;1, :e=&gt;2}, {:d=&gt;4, :e=&gt;2}, {:d=&gt;8, :e=&gt;5}, {:d=&gt;7, :e=&gt;5}], :stuff2=&gt;[{:f=&gt;33, :g=&gt;44}, {:f=&gt;55, :g=&gt;66}, {:f=&gt;45, :g=&gt;89}, {:f=&gt;78, :g=&gt;67}], :h=&gt;4}}}
  </code></pre>
  
  <p>I've found this <a href="https://stackoverflow.com/questions/5413481/ruby-merge-hashes-putting-keys-into-csv-string">post</a>, but my case is with nested hashes, so any help from some good ruby hands would be appreciated.</p>
  
  <p>Basically, I want to "merge" the array values of same named keys <em>when</em> the values corresponding to those keys are <em>arrays</em>.  Of course the following will <strong>replace</strong> <code>hash_1</code>'s <code>:stuff1</code> array with <code>hash_2</code>'s <code>:stuff1</code> array (and similarly for <code>:stuff2</code>), but I want an array '<code>+</code>' type of merge, not an update/replace, or merge! ...</p>
  
  <pre><code>hash_1.merge(hash_2)  # NOT what I want =&gt; {:a=&gt;{:b=&gt;3, :c=&gt;{:stuff1=&gt;[{:d=&gt;8, :e=&gt;5}, {:d=&gt;7, :e=&gt;5}], :stuff2=&gt;[{:f=&gt;45, :g=&gt;89}, {:f=&gt;78, :g=&gt;67}], :h=&gt;4}}}
  </code></pre>
  
  <p>I'm using ruby 1.9.2, btw.  I know hashes have been updated a bit lately, though I don't think that'll affect the answer.</p>
  
  <p>Thanks!</p>