Ruby convert an Array to Hash values with specific keys

Viewed 7836

Is there a way to pull the values from an array and assign them each a unique key in Ruby?

I want to be able to turn this array:

["12", "21", "1985"]

Into this hash:

{:month => "12", :day => "21", :year => "1985"}

I would rather not assign each value individually, like this:

arr = ["12", "21", "1985"]
bday_hash = {:month => arr[0], :day => arr[1], :year => arr[2]}
4 Answers
Related