c4cb978251712512c15ff1942977d2d3d76a1a7e
[ruby_koans.git] / README.rdoc
1 = EdgeCase Ruby Koans
2
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.
8
9 == The Structure
10
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.
14
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.
17
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.
22
23 == Installing Ruby
24
25 If you do not have Ruby setup, please visit http://ruby-lang.org/en/downloads/ for
26 operating specific instructions.  In order to run this you need ruby and rake
27 installed. To check the installations simply type:
28
29 *nix platforms from any terminal window:
30
31    [~] $ ruby --version
32    [~] $ rake --version
33
34 Windows from the command prompt (cmd.exe)
35
36    c:\ruby --version
37    c:\rake --version
38
39 If you don't have rake installed, just run `gem install rake`
40
41 Any response for Ruby with a version number greater than 1.8 is fine (should be
42 around 1.8.6 or more). Any version of rake will do.
43
44 == Generating the Koans
45
46 A fresh checkout will not include the koans, you will need to generate
47 them.
48
49     [ruby_koans] $ rake gen                       # generates the
50     koans directory
51
52 If you need to regenerate the koans, thus wiping your current `koans`,
53
54     [ruby_koans] $ rake regen                     # regenerates the
55     koans directory, wiping the original
56
57 == The Path To Enlightenment
58
59 You can run the tests through rake or by calling the file itself (rake is the
60 recommended way to run them as we might build more functionality into this task).
61
62 *nix platforms, from the koans directory
63
64     [ruby_koans] $ rake                           # runs the default target :walk_the_path
65     [ruby_koans] $ ruby path_to_enlightenment.rb  # simply call the file directly
66
67 Windows is the same thing
68
69     c:\ruby_koans\rake                             # runs the default target :walk_the_path
70     c:\ruby_koans\ruby path_to_enlightenment.rb    # simply call the file directly
71
72 === Red, Green, Refactor
73
74 In test-driven development the mantra has always been, red, green, refactor.  Write a
75 failing test and run it (red), make the test pass (green), then refactor it (that is
76 look at the code and see if you can make it any better.  In this case you will need
77 to run the koan and see it fail (red), make the test pass (green), then take a
78 moment and reflect upon the test to see what it is teaching you and improve the
79 code to better communicate its intent (refactor).
80
81 The very first time you run it you will see the following output:
82
83     [ ruby_koans ] $ rake
84     (in /Users/person/dev/ruby_koans)
85     cd koans
86
87     Thinking AboutAsserts
88       test_assert_truth has damaged your karma.
89
90     You have not yet reached enlightenment ...
91     <false> is not true.
92
93     Please meditate on the following code:
94     ./about_asserts.rb:10:in `test_assert_truth'
95     path_to_enlightenment.rb:27
96
97     mountains are merely mountains
98
99 You have come to your first stage. If you notice it is telling you where to look for
100 the first solution:
101
102     Please meditate on the following code:
103     ./about_asserts.rb:10:in `test_assert_truth'
104     path_to_enlightenment.rb:27
105
106 We then open up the about_asserts.rb file and look at the first test:
107
108     # We shall contemplate truth by testing reality, via asserts.
109     def test_assert_truth
110       assert false                # This should be true
111     end
112
113 We then change the +false+ to +true+ and run the test again.  After you are
114 done, think about what you are learning.  In this case, ignore everything except
115 the method name (+test_assert_truth+) and the parts inside the method (everything
116 before the +end+).
117
118 In this case the goal is for you to see that if you pass a value to the +assert+
119 method, it will either ensure it is +true+ and continue on, or fail if in fact
120 the statement is +false+.
121
122 == Inspiration
123
124 A special thanks to Mike Clark and Ara Howard for inspiring this
125 project.  Mike Clark wrote an excellent blog post about learning Ruby
126 through unit testing. This sparked an idea that has taken a bit to
127 solidify, that of bringing new rubyists into the community through
128 testing. Ara Howard then gave us the idea for the Koans in his ruby
129 quiz entry on Meta Koans (a must for any rubyist wanting to improve
130 their skills).  Also, "The Little Lisper" taught us all the value of
131 the short questions/simple answers style of learning.
132
133 Mike Clark's post ::  http://www.clarkware.com/cgi/blosxom/2005/03/18
134 Meta Koans        ::  http://rubyquiz.com/quiz67.html
135 The Little Lisper ::  http://www.amazon.com/Little-LISPer-Third-Daniel-Friedman/dp/0023397632
136
137 == Other Resources
138
139 The Ruby Language               ::  http://ruby-lang.org
140 Try Ruby in your browser        ::  http://tryruby.org
141
142 Dave Thomas' introduction to Ruby Programming Ruby (the Pick Axe) ::  http://pragprog.com/titles/ruby/programming-ruby
143
144 Brian Marick's fantastic guide for beginners Everyday Scripting with Ruby    ::  http://pragprog.com/titles/bmsft/everyday-scripting-with-ruby
145
146 = Other stuff
147
148 Author         :: Jim Weirich <jim@weirichhouse.org>
149 Author         :: Joe O'Brien <joe@edgecase.com>
150 Issue Tracker  :: http://www.pivotaltracker.com/projects/48111
151 Requires       :: Ruby 1.8.x or later and Rake (any recent version)
152
153 = License
154
155 http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png
156
157 RubyKoans is released under a Creative Commons,
158 Attribution-NonCommercial-ShareAlike, Version 3.0
159 (http://creativecommons.org/licenses/by-nc-sa/3.0/) License.