Ruby 1.9: sexy hashes

I am falling in love with Ruby 1.9 something fierce! There’s a new literal Hash syntax and I am completely smitten!

Here’s a good old Ruby 1.8 hash:

lame_hash = { :o ne => 1, :two => 2, :three => 3 }

And now the new and improved version:

sexy_hash = { one: 1, two: 2, three: 3 }

Damn, beautiful!

  1. Also, hashes are now ordered, just as arrays. Holy cow!

  2. Reminds me of JSON, thats the only reason im not sure i like the new alternative syntax, it is smaller though :) ordered == awesome tho!

  1. No trackbacks yet.