Transforming a hash object in ruby

Curious to know the best way to do this in ruby. I have done it but think Im not doing the best

I have a hash object as follows

{2=>{:name=>"Somename"}, 3=>{:last_name=>"Something"}}

I want to get to

{:name=>"Somename",:last_name=>"Something"}

Answers


input_hash.values.reduce { |h,v| h.merge(v) }

UPDATE: I thought that my answer is shortest but I was wrong, the answer from tokland:

input_hash.values.reduce(:merge)

Need Your Help

retrieve multiples values from a function

javascript function return coordinates

What I'm doing wrong? I trying to retrieve the latitude and longitude values from the function but I receive is undefined.