Ruby from version 1.6 to 1.9

Back in 2002, Ian Macdonald invited Dave Thomas to the Googleplex to give a talk about Ruby. I bought the first version of the Pickaxe book (for Ruby 1.6) and had it autographed for the visit. After the talk, I read the book, slurped the language right up, and started using it in a few projects there. Alas, I had to do it secretly - Google has always been a Python shop - but I had fun with it.

Since then, I've followed the Ruby and Rails crowd, but haven't done much with either besides dabble.

Last week, however, I finally finished reading the ruby 1.9 version of the book. The core of the language is still there, but they have done little improvements here and there to make it more elegant and interesting.

There are too many to list them all, but the most interesting to me are:

  1. Enumerators. You can convert most collections to an Enumerator object with the to_enum method. This allows you to simultaneously iterate through two collections at the same time, or for those other occasions where ruby's built-in interation blocks aren't a good fit.

  2. Encodings. The language now supports separately manipulable encodings for the source code, IO, as well as internal objects.

  3. "Splatting" (expanding a collection in a method call or during parallel assignment) is much cleaner now. Previous versions had too many rules, and weren't intuitive.

  4. Block local variables. One of the gotchas was that "local variables" in a block weren't local if they were defined outside the block. Well, that's still true, but now you can explicitly list block local variables so there is no more accidental overwriting of block external variables.

  5. require_relative. No more "require File.dirname(FILE) + '/../../blah' garbage.

I think Ruby is an interesting language and think it deserves more respect than it gets in some circles. I hope its development community matures and the world's perception of it improves.

posted: Nov 1 2010
tags: ruby