Use a hash constructor in Ruby 1.9?


How would you create a new hash using the hash constructor in Ruby 1.9? The instructions show how to modify literal notation into the new format, so this:

movies = {:Finding_Dory => "10",
    :The_Hereafter => "1",
    :Spirited_Away => "6",
    :Whiskey_Tango_Foxtrot => "8"

turns into this:

movies = {Finding_Dory: "10",
    The_Hereafter: "1"
    Spirited_Away: "6"
    Whiskey_Tango_Foxtrot: "8"

But how would I modify a hash that's been made using the hash constructor?


reference the movies hash with the symbol you want to edit
At least.. I think this is what you're asking..?

movies[:Finding_Dory] = "3"
puts movies[:Finding_Dory]


Not really, actually. I'm just wondering how you would use the hash constructor without using hash rockets. That's probably a better way to phrase my question.



movies = Hash["Finding Dory", "10", "Finding Nemo", "9"]

? This gets a hash without the "rockets"

then again edit with
movies["Finding Dory"] = "2"


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.