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

How do I manually edit the manifest of my Visual Studio project to explicitly specify referenced assemblies?

c# visual-studio-2010 compilation dependencies manifest

Due to a serious headache with log4net's strong naming and versioning, i.e., the old 1.2.10 name, the new 1.2.11 name, and (heaven help me) the 1.2.10 one SAP made and shoved into the GAC with its ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.