My personal dev blog

Thoughts about DevOps stuff and more

Hashes at Ruby1.9 Are Sexy

| Comments

Probably everybody knew that, but I didn’t when I readed at the Programming Ruby book.

I was use to the no so sexy syntax for the hashes in Ruby:

1
numbers = { "one" => "uno", "two" => "dos", "three" => "tres" }

Although is very common to see them at code using symbols as keys and split the elements into lines:

1
2
3
4
5
numbers = {
  :one   => "uno",
  :two   => "dos",
  :three => "tres"
}

which, actually, looks nicer… (at least to me)

But in Ruby 1.9 they decide that if this was so common, maybe it could me a good idea simplify it. So now we can do the same by doing:

1
2
3
4
5
numbers = {
  one:   "uno",
  two:   "dos",
  three: "tres"
}

It is less verbose and, I think, more natural.

Comments