Sunday, 13 April 2008

Likin' RDoc

I've moved onto part 2 of Pickaxe. Currently on the RDoc chapter. I must say I'm impressed how smiple it seems to keep things. No fancy @param annotations to learn, just put a comment above your class / attribute / method and you're off. If you feel the need for more control of your formatting, you can get busy with a very wiki-like syntax.

Its also interesting to note that if you click on a method, RDoc will show you the code. It highlights a key difference between the Java and Ruby worlds.

Sunday, 6 April 2008

Unit Testing in Ruby

Ruby comes with a Unit Test framework pre installed: Nathaniel Talbott's Test::Unit. The Pickaxe book devotes a whole chapter to it (and not at the back). These are good things.

Saturday, 5 April 2008

Ruby I/O - Calling with a block does the .close for me

More Ruby niceness. This should look familiar to all Java guys and gals out there:

Repeat after me: "Always be closing. Always be closing. Always be closing."

But Ruby's can also take a block to associate with the call:

This invokes the block, passes the newly opened file to it as a parameter. When this is complete, the file is automatically closed for you.

In addition to this, if an exception ocurs in the first example then the close will never be called until its GC'd. (Bet you'd miss checked exceptions then). With the second example, the file is closed and then the exception is propogated to the caller.