The syntax for a Hash
literal in ruby is:
{ key => value }
The key
can be any object, including a Symbol
, eg.
{ :foo => "bar" }
Using a symbol for the keys in a hash became so popular, and so idiomatic in ruby that in ruby 1.9 an optional syntax was added for a hash created with symbol keys, and from there on the following is precisely equivalent to the above:
{ foo: "bar" }
Update
Further to your specific use case, ruby also allows you to drop the {}
s when passing the Hash
as an argument to a method (as well as being able to drop the ()
s), so the following are equivalent:
foobar( { foo: "bar" } )
foobar( foo: "bar" )
foobar foo: "bar"
foobar :foo => "bar"