Ruby on Rails ActiveSupport or plain Ruby way of merging arrays into a hash
Posted
by randombits
on Stack Overflow
See other posts from Stack Overflow
or by randombits
Published on 2010-04-18T17:27:52Z
Indexed on
2010/04/18
17:33 UTC
Read the original article
Hit count: 624
ruby-on-rails
|ruby
What's a smart way of using ActiveSupport or perhaps regular built in Ruby functionality to take two arrays and merge them into a hash where each element in an array matches the element in a parallel array? imagine two arrays:
names = ["Danny", "Johnny"]
ages = ["25", "32"]
The end result should be a hash that looks like:
{"Danny" => "25", "Johnny" => "32"}
© Stack Overflow or respective owner