In Rails: I like to convert
my_arrow_hash = {:a=>1,:b=>2,:c=>3}
to
My_colon_hash = {a: 1, b: 2, c: 3}
The two are identical. They both declare a hash with keys that are ruby symbols :a
, :b
, and :c
.
The first declaration ({:a=>1,:b=>2,:c=>3}
) uses the traditional ruby syntax to declare the hash.
The second declaration ({a: 1, b: 2, c: 3}
) uses a newer and shorter syntax that was introduced in Ruby 1.9 and can only be used when the keys are ruby symbols.