title: Merge hashes with multiple keys/values
body: <p>I have an array of hashes of which I merge hashes that contain specific duplicate key value. </p>
  
  <pre><code>combined_keywords = new_array_of_hashes.each_with_object(Hash.new(0)){|oh, newh|
          newh[oh[:keyword]] += oh[:total_value].to_f
      }
  </code></pre>
  
  <p>This creates an array of hashes that look like this:</p>
  
  <pre><code> { :ACTUAL_KEYWORD =&gt; ACTUAL_TOTAL_VALUE }
  </code></pre>
  
  <p>I'm new to ruby and I don't quite understand the magic behind this. I have an additional key and value to consolidate and now I'm lost. The root of the issue is I don't understand how the consolidation is occurring in this line: <code>newh[oh[:keyword]] += oh[:total_value].to_f</code></p>
  
  <p>I tried this with no luck:</p>
  
  <pre><code>combined_keywords = new_array_of_hashes.each_with_object(Hash.new(0)){|oh, newh|
              newh[oh[:keyword]] += oh[:total_value].to_f
              newh[oh[:keyword]] += oh[:revenue_per_transaction].to_f
          }
  </code></pre>
  
  <p>I really just need an array of consildated hashes each similar to:</p>
  
  <pre><code>{ :keyword =&gt; "ACTUAL_KEYWORD", :total_value =&gt; ACTUAL_TOTAL_VALUE, :revenue_per_transaction =&gt; ACTUAL_REVENUE }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>Input</p>
  
  <pre><code>new_array_of_hashes = [
    { keyword: 'foo', total_value: 1, revenue_per_transaction: 5 },
    { keyword: 'bar', total_value: 2, revenue_per_transaction: 4 },
    { keyword: 'bar', total_value: 4, revenue_per_transaction: 4 },
    { keyword: 'foo', total_value: 3, revenue_per_transaction: 5 },
  ]
  </code></pre>
  
  <p>Desired Output</p>
  
  <pre><code>combined_keywords = [
    { keyword: 'foo', total_value: 4, revenue_per_transaction: 10 },
    { keyword: 'bar', total_value: 6, revenue_per_transaction: 8 },
  ]
  </code></pre>