Sunday, July 30, 2006

Ruby Blocks

I commented on how I think Ruby Blocks are pretty sweet to my friend Erik and he responded:

come on dude, you sure you wouldn't rather type:

File f = null;

try
{
    f = File.open("/tmp/bs");
    //do-stuff
}
catch(IOException ioe)
{
    //die!
}
finally
{
    if(null != f)
    {
        try
        {
            f.close();
        }
        catch(Exception e)
        {
            //eat-it
        }
    }
}

than:

File.open("/tmp/bs") { |file| //do stuff }

(that's my favorite example btw)

Yeah, so I like blocks better then the above ;)

1 comment:

ebc said...

Next thing you know, you'll be making little sniping remarks about Java like that one dropped at the OSCON Streamlined talk: "Right about now, your average Java developer is wetting himself." ;)