«

»

Oct 06

Just because I Koan

If you have some ice cream,
I will give it to you.
If you have no ice cream,
I will take it away from you.
It is an ice cream koan.

Ruby Metakoans

In software, koans are a form of kata, or practice. There are a number of these; one of the first I’d encountered is the Ruby Quiz – metakoans.rb (#67). I’d first solved it eight or nine years ago, but decided to do it again to brush up on my skills. In the intervening years, there have been a few changes to Ruby, but only one real change needed to be made:

First time it took me a few hours to write. This time, it took less than an hour to get it working… amazing the difference time makes. Also, as I (dimly) recall my previous version was not as maintainable — I used a lot of instance_eval rather than define_method as I did this time. But I don’t want to give any more away in case y’all might want to give it a try.

spoilers I’m putting my solution here (with a patched metakoans.rb): download.

Neo Ruby Koans

A more general ruby language practice is Neo’s Ruby Koans. It’s inspired, in part, by the metakoans. This one is a bit longer — there are approximately 280 separate tests/exercises. That one is geared more toward people who are first learning, but there were some things which I don’t remember having come across before. A good exercise, all in all.

I’m going to look for some more koans…..

Leave a Reply

%d bloggers like this: