ran through the Ruby Koans

I did most of the Ruby Koans last night and finished it up today.


Most of it felt ‘right’ (at least with my history in perl/python/etc) although a few of them seemed a bit odd (at least in 1.9.3 behavior).

The ones that stuck out as odd (at least, IMHO) were:

array slicing with the first index that is invalid

This is a test that passes:

I’m assuming there’s a particular use case (and/or legacy behavior) behind that, but it seemed odd to me.

‘here’ docs differing based on delimiters

The koans included showing how ruby can do ‘here docs’ (inline multi-line strings) with ‘flexible quoting’ which made them easier to deal with depending on the content of the string.

However, I was surprised to find it gives you different behavior than what would appear to be the equivalent ‘here doc’ since it keeps the initial newline.

Now, I could see this being intentional since the older ‘here doc’ format has been around for awhile, and for the flexible quoting to not include the first newline would seem very odd to those not thinking of it as another form of ‘here doc’ (since the quoting starts before that first newline, after all), but in terms of showing it as “here’s another way you can do X”, it struck me, at least initially, as odd. 🙂