title: Ruby: Sum selected hash values
body: <p>I've got an array of hashes and would like to sum up selected values. I know how to sum all of them or one of them but not how to select more than one key.</p>
  
  <p>i.e.:</p>
  
  <pre><code>[{"a"=&gt;5, "b"=&gt;10, "active"=&gt;"yes"}, {"a"=&gt;5, "b"=&gt;10, "active"=&gt;"no"}, {"a"=&gt;5, "b"=&gt;10, "action"=&gt;"yes"}] 
  </code></pre>
  
  <p>To sum all of them I using:</p>
  
  <pre><code>t = h.inject{|memo, el| memo.merge( el ){|k, old_v, new_v| old_v + new_v}}
  =&gt; {"a"=&gt;15, "b"=&gt;30, "active"=&gt;"yesnoyes"} # I do not want 'active'
  </code></pre>
  
  <p>To sum one key, I do:</p>
  
  <pre><code>h.map{|x| x['a']}.reduce(:+)
  =&gt; 15 
  </code></pre>
  
  <p>How do I go about summing up values for keys 'a' and 'b'?</p>