How do I use the new hash style with numbers as keys?
I have:
{ 1 => "terrible", 3=> "OK", 5 => "awesome" }
But I'd like to know how to write them using the new hash style.
How do I use the new hash style with numbers as keys?
I have:
{ 1 => "terrible", 3=> "OK", 5 => "awesome" }
But I'd like to know how to write them using the new hash style.
You don't, to use the new syntax you must use a subset of valid symbols. Numbers aren't that, and as Mu points out, there are other restrictions as well.
Your key is a number, not a symbol. With the new hash style of {key: value}
the key is always supposed to be a symbol, so you can't use the new hash style with your hash because your keys start with numbers, not symbols. See "Update your entire project to Ruby 1.9 hash syntax" where it explicitly states:
In version 1.9 Ruby introduced new syntax for hash literals whose keys are symbols.