Arrays of hashes to hash Task: convert this array of hashes:

animals = [
  {"cats" =&gt; 3},
  {"dogs" =&gt; 5 }
]


to this hash:

{
  "cats" =&gt; 3,
  "dogs" =&gt; 5
}


This is my solution, any feedback is appreciated :-)

animals.reduce({}) {|m,e|
  e.each{|k,v| m[k] = v}; m
}
The snippet e.each{|k,v| m[k] = v} does the same thing as the standard library method Hash#merge!, so the shortest way to write your solution is probably:

animals.reduce({}, :merge!)


Note that with this solution, if two hashes in the source array have duplicate keys, those coming later in the array will take priority and overwrite the duplicate keys from earlier in the array:

[{"egrets" =&gt; 17}, {"egrets" =&gt; 21}].reduce({}, :merge!)  # =&gt; {"egrets"=&gt;21}


Also be aware that merge! is destructive to the original hash, which is fine here since we don't reuse the literal input to reduce. There is a non-destructive version, merge, which is better when the input needs to be preserved.