I am creating a Ruby hash for movie names storage.
When the hash's keys are strings that contains whitespaces, it works just fine.
As in:
movies = {"Avatar" => 5, "Lord of the rings" => 4, "Godfather" => 4}
Now I am trying to replace the use of strings with symbols:
movies = {Avatar: 5, Lord of the rings: 4, Godfather: 4}
Obviously that doesn't work.
How does Ruby handle whitespaces in symbol naming?
Late to the party, but another way to get around this is to do the following:
I'm not sure why you want to use symbols when you want spaces in the key values, but you can do that. You just can't do it using the
<symbol>: <value>
syntax...Try by yourself
To make a symbol with spaces, enter a colon followed by a quoted String. For your example, you would enter: