README.rdoc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. = Neo Ruby Koans
  2. The Ruby Koans walk you along the path to enlightenment in order to learn Ruby.
  3. The goal is to learn the Ruby language, syntax, structure, and some common
  4. functions and libraries. We also teach you culture by basing the koans on tests.
  5. Testing is not just something we pay lip service to, but something we
  6. live. Testing is essential in your quest to learn and do great things in Ruby.
  7. == The Structure
  8. The koans are broken out into areas by file, hashes are covered in +about_hashes.rb+,
  9. modules are introduced in +about_modules.rb+, <em>etc</em>. They are presented in
  10. order in the +path_to_enlightenment.rb+ file.
  11. Each koan builds up your knowledge of Ruby and builds upon itself. It will stop at
  12. the first place you need to correct.
  13. Some koans simply need to have the correct answer substituted for an incorrect one.
  14. Some, however, require you to supply your own answer. If you see the method +__+ (a
  15. double underscore) listed, it is a hint to you to supply your own code in order to
  16. make it work correctly.
  17. == Installing Ruby
  18. If you do not have Ruby setup, please visit http://ruby-lang.org/en/downloads/ for
  19. operating specific instructions. In order to run the koans you need +ruby+ and
  20. +rake+ installed. To check your installations simply type:
  21. *nix platforms from any terminal window:
  22. [~] $ ruby --version
  23. [~] $ rake --version
  24. Windows from the command prompt (+cmd.exe+)
  25. c:\ruby --version
  26. c:\rake --version
  27. If you don't have +rake+ installed, just run <code>gem install rake</code>
  28. Any response for Ruby with a version number greater than 1.8 is fine (should be
  29. around 1.8.6 or more). Any version of +rake+ will do.
  30. == Generating the Koans
  31. A fresh checkout will not include the koans, you will need to generate
  32. them.
  33. [ruby_koans] $ rake gen # generates the koans directory
  34. If you need to regenerate the koans, thus wiping your current `koans`,
  35. [ruby_koans] $ rake regen # regenerates the koans directory, wiping the original
  36. == The Path To Enlightenment
  37. You can run the tests through +rake+ or by calling the file itself (+rake+ is the
  38. recommended way to run them as we might build more functionality into this task).
  39. *nix platforms, from the +ruby_koans+ directory
  40. [ruby_koans] $ rake # runs the default target :walk_the_path
  41. [ruby_koans] $ ruby path_to_enlightenment.rb # simply call the file directly
  42. Windows is the same thing
  43. c:\ruby_koans\rake # runs the default target :walk_the_path
  44. c:\ruby_koans\ruby path_to_enlightenment.rb # simply call the file directly
  45. === Red, Green, Refactor
  46. In test-driven development the mantra has always been <em>red, green, refactor</em>.
  47. Write a failing test and run it (<em>red</em>), make the test pass (<em>green</em>),
  48. then look at the code and consider if you can make it any better (<em>refactor</em>).
  49. While walking the path to Ruby enlightenment you will need to run the koan and
  50. see it fail (<em>red</em>), make the test pass (<em>green</em>), then take a moment
  51. and reflect upon the test to see what it is teaching you and improve the code to
  52. better communicate its intent (<em>refactor</em>).
  53. The very first time you run the koans you will see the following output:
  54. [ ruby_koans ] $ rake
  55. (in /Users/person/dev/ruby_koans)
  56. /usr/bin/ruby1.8 path_to_enlightenment.rb
  57. AboutAsserts#test_assert_truth has damaged your karma.
  58. The Master says:
  59. You have not yet reached enlightenment.
  60. The answers you seek...
  61. <false> is not true.
  62. Please meditate on the following code:
  63. ./about_asserts.rb:10:in `test_assert_truth'
  64. path_to_enlightenment.rb:38:in `each_with_index'
  65. path_to_enlightenment.rb:38
  66. mountains are merely mountains
  67. your path thus far [X_________________________________________________] 0/280
  68. You have come to your first stage. Notice it is telling you where to look for
  69. the first solution:
  70. Please meditate on the following code:
  71. ./about_asserts.rb:10:in `test_assert_truth'
  72. path_to_enlightenment.rb:38:in `each_with_index'
  73. path_to_enlightenment.rb:38
  74. Open the +about_asserts.rb+ file and look at the first test:
  75. # We shall contemplate truth by testing reality, via asserts.
  76. def test_assert_truth
  77. assert false # This should be true
  78. end
  79. Change the +false+ to +true+ and re-run the test. 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
  82. before the +end+).
  83. In this case the goal is for you to see that if you pass a value to the +assert+
  84. method, it will either ensure it is +true+ and continue on, or fail if
  85. the statement is +false+.
  86. === Running the Koans automatically
  87. <em>This section is optional.</em>
  88. Normally the path to enlightenment looks like this:
  89. cd ruby_koans
  90. rake
  91. # edit
  92. rake
  93. # edit
  94. rake
  95. # etc
  96. If you prefer, you can keep the koans running in the background so that after you
  97. make a change in your editor, the koans will immediately run again. This will
  98. hopefully keep your focus on learning Ruby instead of on the command line.
  99. Install the Ruby gem (library) called +watchr+ and then ask it to
  100. "watch" the koans for changes:
  101. cd ruby_koans
  102. rake
  103. # decide to run rake automatically from now on as you edit
  104. gem install watchr
  105. watchr ./koans/koans.watchr
  106. == Inspiration
  107. A special thanks to Mike Clark and Ara Howard for inspiring this
  108. project. Mike Clark wrote an excellent blog post about learning Ruby
  109. through unit testing. This sparked an idea that has taken a bit to
  110. solidify, that of bringing new rubyists into the community through
  111. testing. Ara Howard then gave us the idea for the Koans in his ruby
  112. quiz entry on Meta Koans (a must for any rubyist wanting to improve
  113. their skills). Also, "The Little Lisper" taught us all the value of
  114. the short questions/simple answers style of learning.
  115. Mike Clark's post :: http://www.clarkware.com/cgi/blosxom/2005/03/18
  116. Meta Koans :: http://rubyquiz.com/quiz67.html
  117. The Little Lisper :: http://www.amazon.com/Little-LISPer-Third-Daniel-Friedman/dp/0023397632
  118. == Other Resources
  119. The Ruby Language :: http://ruby-lang.org
  120. Try Ruby in your browser :: http://tryruby.org
  121. Dave Thomas' introduction to Ruby Programming Ruby (the Pick Axe) :: http://pragprog.com/titles/ruby/programming-ruby
  122. Brian Marick's fantastic guide for beginners Everyday Scripting with Ruby :: http://pragprog.com/titles/bmsft/everyday-scripting-with-ruby
  123. = Other stuff
  124. Author :: Jim Weirich <jim@neo.org>
  125. Author :: Joe O'Brien <joe@objo.com>
  126. Issue Tracker :: http://www.pivotaltracker.com/projects/48111
  127. Requires :: Ruby 1.8.x or later and Rake (any recent version)
  128. = License
  129. http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png
  130. RubyKoans is released under a Creative Commons,
  131. Attribution-NonCommercial-ShareAlike, Version 3.0
  132. (http://creativecommons.org/licenses/by-nc-sa/3.0/) License.