Learn Ruby With the Edgecase Ruby Koans The Koans walk you along the path to enlightenment in order to learn Ruby. The goal is to learn the Ruby language, syntax, structure, and some common functions and libraries. We also teach you culture. Testing is not just something we pay lip service to, but something we live. It is essential in your quest to learn and do great things in the language.

The Structure The koans are broken out into areas by file, hashes are covered in about_hashes.rb, modules are introduced in about_modules.rb, etc. They are presented in order in the path_to_enlightenment.rb file. Each koan builds up your knowledge of Ruby and builds upon itself. It will stop at the first place you need to correct. Some koans simply need to have the correct answer substituted for an incorrect one. Some, however, require you to supply your own answer. If you see the method __ (a double underscore) listed, it is a hint to you to supply your own code in order to make it work correctly.

Installing Ruby These instructions are for *nix platforms. We also have Windows instructions . In order to run the koans you need Ruby installed. If you do not already have Ruby setup, please visit http://ruby-lang.org/en/downloads for operating system specific instructions. To verify your installation, in your terminal window simply type: $ ruby --version Any response for Ruby with a version number greater than 1.8 is fine.

What Editors Can I Use? These instructions are for *nix platforms. We also have Windows instructions . You can really use any editor you'd like, but here are some suggestions: Emacs

TextMate

Vim

RubyMine

VSCode

The Path to Enlightenment These instructions are for *nix platforms. We also have Windows instructions . You can run the tests by calling the path_to_enlightenment.rb file. In your terminal, while in the ruby_koans directory, type: [ ruby_koans ] $ ruby path_to_enlightenment.rb Red, Green, Refactor In test-driven development (TDD) the mantra has always been red: write a failing test and run it, green: make the test pass, and refactor: look at the code and see if you can make it any better. With the koans, you will need to run the tests and see it fail (red), make the test pass (green), then take a moment and reflect upon the test to see what it is teaching you and improve the code to better communicate its intent (refactor). The very first time you run it you will see the following output: [ ruby_koans ] $ ruby path_to_enlightenment.rb

(in /Users/person/dev/ruby_koans)

cd koans Thinking AboutAsserts

test_assert_truth has damaged your karma. You have not yet reached enlightenment ...

<false> is not true. Please meditate on the following code:

./about_asserts.rb:10:in `test_assert_truth'

path_to_enlightenment.rb:27 mountains are merely mountains You have come to the first error. Notice you are told where to look for the error: Please meditate on the following code:

./about_asserts.rb:10:in `test_assert_truth'

path_to_enlightenment.rb:27 You then open up the about_asserts.rb file in your text editor and look at line 10: # We shall contemplate truth by testing reality, via asserts.

def test_assert_truth

assert false # This should be true

end You then change false to true and run the tests again. You should get a new error. Before moving on, think about what you are learning. In this specific case, ignore everything except the method name (test_assert_truth) and the parts inside the method (everything before the end). The goal is for you to see that if you pass a value to the assert method, it will either ensure it is true and continue on, or fail if in fact the statement is false.

License Ruby Koans is released under a Creative Commons, Attribution-NonCommercial-ShareAlike License. @jimweirich



Inspiration A special thanks to Mike Clark and Ara Howard for inspiring this project. Mike Clark wrote an excellent blog post about learning Ruby through unit testing. This sparked an idea that has taken a bit to solidify, that of bringing new rubyists into the community through testing. Ara Howard then gave us the idea for the Koans in his ruby quiz entry on Meta Koans (a must for any rubyist wanting to improve their skills). Also, "The Little Lisper" taught us all the value of the short questions/simple answers style of learning. Mike Clark's post https://pragmaticstudio.com/blog/2005/03/18/ruby-learning-test-1-are-you-there-world Meta Koans rubyquiz.com/quiz67.html The Little Lisper amazon.com/Little-LISPer-Third-Daniel-Friedman/dp/0023397632 Coda - the Ruby Koans were principally the work of ( Jim Weirich ) while working at EdgeCase. Jim was an incredible influence in the Ruby community and beyond. And as good as he was as a developer, he was an even better human being. Jim sadly passed away in 2014. We all still miss him terribly and maintain this site in his honor.

Mountains are merely mountains