3 The Ruby Koans walk you along the path to enlightenment in order to learn Ruby.
4 The goal is to learn the Ruby language, syntax, structure, and some common
5 functions and libraries. We also teach you culture. Testing is not just something we
6 pay lip service to, but something we live. It is essential in your quest to learn
7 and do great things in the language.
11 The koans are broken out into areas by file, hashes are covered in about_hashes.rb,
12 modules are introduced in about_modules.rb, etc. They are presented in order in the
13 path_to_enlightenment.rb file.
15 Each koan builds up your knowledge of Ruby and builds upon itself. It will stop at
16 the first place you need to correct.
18 Some koans simply need to have the correct answer substituted for an incorrect one.
19 Some, however, require you to supply your own answer. If you see the method __ (a
20 double underscore) listed, it is a hint to you to supply your own code in order to
21 make it work correctly.
24 == The Path To Enlightenment
26 In order to achieve enlightenment you need to follow the path_to_enlightenment. This
27 can be done in two ways
29 *nix platforms, from the koans directory
31 [ruby_koans] $ rake # runs the default target :walk_the_path
32 [ruby_koans] $ ruby path_to_enlightenment.rb # simply call the file directly
34 Windows is the same thing
36 c:\ruby_koans\rake # runs the default target :walk_the_path
37 c:\ruby_koans\ruby path_to_enlightenment.rb # simply call the file directly
39 === Red, Green, Refactor
41 In test-driven development the mantra has always been, red, green, refactor. Write a
42 failing test and run it (red), make the test pass (green), then refactor it (that is
43 look at the code and see if you can make it any better. In this case you will need
44 to run the koan and see it fail (refactor), make the test pass (green), then take a
45 moment and reflect upon the test to see what it is teaching you.
47 The very first time you run it you will see the following output:
50 (in /Users/person/dev/ruby_koans)
54 test_assert_truth has damaged your karma.
56 You have not yet reached enlightenment ...
59 Please meditate on the following code:
60 ./about_basics.rb:10:in `test_assert_truth'
61 path_to_enlightenment.rb:27
63 mountains are merely mountains
65 You have come to your first stage. If you notice it is telling you where to look for
68 Please meditate on the following code:
69 ./about_basics.rb:10:in `test_assert_truth'
70 path_to_enlightenment.rb:27
72 We then open up the about_basics.rb file and look at the first test:
74 # We shall contemplate truth by testing reality, via asserts.
76 assert false # This should be true
79 We then change the +false+ to +true+ and run the test again. After you are
80 done, think about what you are learning. In this case, ignore everything except
81 the method name (+test_assert_truth+) and the parts inside the method (everything
84 In this case the goal is for you to see that if you pass a value to the +assert+
85 method, it will either ensure it is +true+ and continue on, or fail if in fact
86 the statement is +false+.
90 A special thanks to Mike Clark and Ara Howard for inspiring this project. Mike Clark
91 wrote an excellent blog post about learning Ruby through unit testing. This sparked
92 an idea that has taken a bit to solidify, that of bringing new rubyists into the
93 community through testing. Ara Howard then gave us the idea for the Koans in his
94 ruby quiz entry an Meta Koans (a must for any rubyist wanting to improve their skills).
96 Mike Clark's post :: http://www.clarkware.com/cgi/blosxom/2005/03/18
97 Meta Koans :: http://rubyquiz.com/quiz67.html
101 The Ruby Language :: http://ruby-lang.org
103 Dave Thomas' introduction to Ruby
104 Programming Ruby (the Pick Axe) :: http://pragprog.com/titles/ruby/programming-ruby
106 Brian Marick's fantastic guide for beginners
107 Everyday Scripting with Ruby :: http://pragprog.com/titles/bmsft/everyday-scripting-with-ruby
109 Try Ruby in your browser :: http://tryruby.hobix.com/