tags:

views:

116

answers:

2

What's the most most ruby-like way of converting from an Array like [:one, 1, :two, 2] to a Hash like {:one => 1, :two => 2}?

+15  A: 

Here's how I would do it:

Hash[*array]
ACoolie
Wow that's great, I never knew of that syntax before!
Ryan Bigg
+1  A: 
Hash[*[:one, 1, :two, 2]]
#=> {:one => 1, :two => 2}
obvio171