February 5th, 2007

How Ruby has blown my mind

I'm posting this entry for Blogging Challenge - February contest

For me the blow-my-mind Ruby features are:

- first of all (as probably for many others) - blocks.
Its a totally cool feature man ... elegant and very useful.

I came to Ruby from BASIC -> Turbo Pascal -> UNIX and DOS C -> Java -> Python (and liked and still like all of them - yeah - even BASIC! its good to whip up some quick code in ..., though I hardly use it nowadays). I don't know of any such feature (like blocks) in those languages, though there may be - I'm not a language lawyer, just a fan ...

- open classes are a pretty good feature too (though there is a possibility of their use leading to less readable/maintainable code).

- really like attr_accessor and its ilk too; the ability to call getters and setters as though they're fields of an object shortens code ...

- and last but not least, "everything in Ruby is an object" is a great one as well - one example being:

irb: some_instance_or_class.methods.sort
(or .public_methods.sort or ...)

to get a quick idea of a class's methods. Due to Ruby's Principle of Least Surprise, just with this much info, one can often make use of the needed methods, without having to read up the docs.

- Vasudev Ram