Apr 232012
Ruby 1.9 has a cool hash syntax which is quite similar to javascript, so the following hash
hash = {:symbol => "value"}
can be written as
hash = {symbol: "value"}
now, what if both key & values are symbols, in ruby 1.8 & before you would write
:pick => :any
but now, this could be written in short form as
pick: :any
And this both new & old syntax for hash are supported in ruby 1.9, you can use whatever syntax you are comfortable the most but it helps to know both forms of syntax specially when reading the code that other might have written. personally, I like the new one — fewer characters to type
PS: this new has syntax is applicable only if the key is a :symbol. In case when key is not a symbol. you have to still stick with old array syntax(=>)
Related posts: