Ah, back to Ruby. Unfortunately, I had to take several days off for personal reasons…or rather, work invading on personal time. Ugh.

But enough of that nonsense.

This day of Ruby is a short one: exceptions and iterations.

Exceptions

I’ll be perfectly honest: I’m lost on this one. I understand parts of it (for example, that particular errors…like StandardError…are subclasses of other errors), but this is a good example where I think the Koans (or probably my brain) come a little short. If I were to stop here, I’d be completely lost when it comes to handling exceptions in Ruby.

Fortunately, the internet exists, and a quick Google reveals that there a dozens of good articles (like this one) about exception handling in Ruby. So I’ve got some reading to do. And you know what? That’s okay. Part of learning is getting frustrated, hitting a wall, and seeking out the answers. I expected this all along, so no biggie.

Iterations

The Iterations Koan is all about looping over arrays and collections (which have the same methods for iterations, btw). As one might exepct, you have most of the standard operations, like “each”, “find”, “select”, etc. The syntax is pretty straightforward:

myarray = ['one', 'two', 'three']
myarray.collect { |item| 'twenty-' + item}
// gives us => ['twenty-one', 'twenty-two', 'twenty-three']

In this example, I’m using the array’s “collect” method to transform each individual element in the array. Pretty nifty.

Wrapping Up

Well, that was short and sweet. I’m [hopefully] diving back more full-time into Ruby tomorrow, so should have some more cool stuff to share soon. I <3 Ruby :)