1. Computing

The Zen of Learning Ruby


1 of 3

The Zen of Learning Ruby

Learning Ruby isn't often thought of as a Zen exercise, but that's exactly how the guys at EdgeCase saw it. Thus RubyKoans was born.

A Koan is a Buddhist idea. A Koan presents a situation, dialog, statement, story or question that must be thought about. Many of these questions cannot be answered outright, having multiple interpretations. Koans are all very philisophical, but luckily, RubyKoans is quite grounded.

A Koan in RubyKoans is a small demonstration of a feature of Ruby with something missing. You have to fill in that missing piece in order to move on to the next Koan. These Koans are thinking exercises, you have to understand how the language feature works before you can move on.

RubyKoans is perhaps a bit difficult to understand, so here's a Koan. See that double underscore on the last line? You have to fill that in with a value that will make the test case pass. In order to do that, you have to understand true, false and the unless keyword. Pretty neat, isn't it? There are hundreds of Koans in RubyKoans, and they explore Ruby's features quite deeply.

def test_unless_statement_modifier
  result = :default_value
  result = :false_value unless false

  assert_equal __, result

If you're familiar with Ruby programming, you'll see right away what RubyKoans really is. It's a collection of tests to teach Ruby with test driven development. It sounds odd, but it's surprisingly easy and effective.

©2014 About.com. All rights reserved.