RubyKoans: 透過單元測試來學習 Ruby 語法 所推出的 Ruby 學習工具。它的特別之處在於它是用單元測試填空題的方式來認識Ruby語法。要執行很簡單,下載之後,輸入 rake 就會開始跑測試了(如何安裝Ruby請參考這裡),例如以下的測試:

  def test_arrays_and_ranges
    assert_equal __, (1..5).class
    assert_not_equal Array, (1..5)
    assert_equal __, (1..5).to_a
    assert_equal __, (1...5).to_a

其中 __ 的地方就是你要解答的部份,因為是空的,所以顯然測試不會通過(Red),它會提示你那一行出錯,然後實際的值是什麼:

~/koans] (master) .rvm-$ rake
/Users/ihower/.rvm/rubies/ruby-1.9.2-p290/bin/ruby path_to_enlightenment.rb
AboutArrays#test_arrays_and_ranges has damaged your karma.

The Master says:
  You have not yet reached enlightenment.
  You are progressing. Excellent. 20 completed.

The answers you seek...
  <"FILL ME IN"> expected but was  .

Please meditate on the following code:
  /Users/ihower/koans/about_arrays.rb:48:in `test_arrays_and_ranges'

mountains are merely mountains
your path thus far [...X______________________________________________] 20/274


One reply on “RubyKoans: 透過單元測試來學習 Ruby 語法”

Leave a Reply

Your email address will not be published. Required fields are marked *