updated koans with latest src
This commit is contained in:
@@ -36,6 +36,8 @@ Windows from the command prompt (cmd.exe)
|
||||
c:\ruby --version
|
||||
c:\rake --version
|
||||
|
||||
If you don't have rake installed, just run `gem install rake`
|
||||
|
||||
Any response for Ruby with a version number greater than 1.8 is fine (should be
|
||||
around 1.8.6 or more). Any version of rake will do.
|
||||
|
||||
@@ -130,7 +132,15 @@ Brian Marick's fantastic guide for beginners Everyday Scripting with Ruby ::
|
||||
|
||||
= Other stuff
|
||||
|
||||
Author :: Jim Weirich <jim@weirichhouse.org>
|
||||
Author :: Joe O'Brien <joe@edgecase.com>
|
||||
Author :: Jim Weirich <jim@weirichhouse.org>
|
||||
Author :: Joe O'Brien <joe@edgecase.com>
|
||||
Issue Tracker :: http://www.pivotaltracker.com/projects/48111
|
||||
Requires :: Ruby 1.8.x or later and Rake (any recent version)
|
||||
|
||||
= License
|
||||
|
||||
http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png
|
||||
|
||||
RubyKoans is released under a Creative Commons,
|
||||
Attribution-NonCommercial-ShareAlike, Version 3.0
|
||||
(http://creativecommons.org/licenses/by-nc-sa/3.0/) License.
|
||||
|
||||
@@ -1,18 +1,32 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutIteration < EdgeCase::Koan
|
||||
|
||||
# -- An Aside ------------------------------------------------------
|
||||
# Ruby 1.8 stores names as strings. Ruby 1.9 stores names as
|
||||
# symbols. So we use a version dependent method "as_name" to convert
|
||||
# to the right format in the koans. We will use "as_name" whenever
|
||||
# comparing to lists of methods.
|
||||
|
||||
in_ruby_version("1.8") do
|
||||
def test_each_is_a_method_on_arrays
|
||||
assert_equal __, [].methods.include?("each")
|
||||
def as_name(name)
|
||||
name.to_s
|
||||
end
|
||||
end
|
||||
|
||||
in_ruby_version("1.9") do
|
||||
def test_each_is_a_method_on_arrays
|
||||
assert_equal __, [].methods.include?(:each)
|
||||
def as_name(name)
|
||||
name.to_sym
|
||||
end
|
||||
end
|
||||
|
||||
# Ok, now back to the Koans.
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
def test_each_is_a_method_on_arrays
|
||||
assert_equal __, [].methods.include?(as_name(:each))
|
||||
end
|
||||
|
||||
def test_iterating_with_each
|
||||
array = [1, 2, 3]
|
||||
sum = 0
|
||||
@@ -72,7 +86,7 @@ class AboutIteration < EdgeCase::Koan
|
||||
result = [2, 3, 4].inject(0) { |sum, item| sum + item }
|
||||
assert_equal __, result
|
||||
|
||||
result2 = [2, 3, 4].inject(1) { |product, item| product * item }
|
||||
result2 = [2, 3, 4].inject(1) { |sum, item| sum * item }
|
||||
assert_equal __, result2
|
||||
|
||||
# Extra Credit:
|
||||
|
||||
Reference in New Issue
Block a user