Tuesday, 23 November 2010

Ruby Tuesday

The chapter for day 2 is a chunk longer than day 1, so with only a limited amount of time I did not manage to complete it. I did like what I saw though.

The first thing that jumped out at me was in array access. Given a plain old array like a=['first', 'second', 'third'] I’m entirely used to the concept of a[0] being ‘first’ a[1] ‘second’ etc. but have never seen the reverse indexing feature whereby a[-1] is ‘third’ and that delighted me.

I have seen snippets of Ruby like 3.times <blah blah blah> before and quite liked the flow that it lead to, but being able to assign a number to a variable and then use it in the same manner, like:
>> b=5
=> 5
>> b.times {puts "rockin the b"}
rockin the b
rockin the b
rockin the b
rockin the b
rockin the b
was another pleasing experience, as it seems more useful than just being able to run it on numeric literals.

After this we moved on the a custom implementation of the times method that we added to the Fixnum class using the yield keyword to execute the blocks of code. I quite liked the introduction of extension methods in .net for the ability to add handy methods to classes, so seeing this part of the dynamic nature of Ruby was another good thing.

I’ve got a little way to go yet before I even reach the next set of exercises, but again I found myself expanding on the samples given in the book which is a good sign that I’m feeling interested and engaged in what’s happening, and helps to make that learning start to stick. I had been contemplating trying to squeeze some IronRuby into some personal projects that I have been planning, so this bodes well for that.

So far, the only thing that I don’t like about Ruby is that it seems to favour the use of the underscore in naming conventions. I’ve long been a fan of the camel/pascal case conventions used in .net land if only for the simpler typing and shorter names that it provides. Ho hum, it can’t all be hugs and puppies.

No comments:

Post a Comment