Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Windows from the command prompt (+cmd.exe+)

If you don't have +rake+ installed, just run <code>gem install rake</code>

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.
Any response for Ruby with a version number greater than 1.9 is fine. Any version of
+rake+ will do.

== Generating the Koans

Expand Down
4 changes: 2 additions & 2 deletions src/about_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_instance_variables_can_be_set_by_assigning_to_them
assert_equal __([]), fido.instance_variables

fido.set_name("Fido")
assert_equal __(["@name"], [:@name]), fido.instance_variables
assert_equal __([:@name]), fido.instance_variables
end

def test_instance_variables_cannot_be_accessed_outside_the_class
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_inspect_provides_a_more_complete_string_version
def test_all_objects_support_to_s_and_inspect
array = [1,2,3]

assert_equal __("123", "[1, 2, 3]"), array.to_s
assert_equal __("[1, 2, 3]"), array.to_s
assert_equal __("[1, 2, 3]"), array.inspect

assert_equal __("STRING"), "STRING".to_s
Expand Down
2 changes: 1 addition & 1 deletion src/about_hashes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_accessing_hashes
def test_accessing_hashes_with_fetch
hash = { :one => "uno" }
assert_equal __("uno"), hash.fetch(:one)
assert_raise(___(IndexError, KeyError)) do
assert_raise(___(KeyError)) do
hash.fetch(:doesnt_exist)
end

Expand Down
23 changes: 1 addition & 22 deletions src/about_iteration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,8 @@

class AboutIteration < Neo::Koan

# -- An Aside ------------------------------------------------------
# Ruby 1.8 stores names as strings. Ruby 1.9 and later 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 as_name(name)
name.to_s
end
end

in_ruby_version("1.9", "2", "3", "4") do
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 __(true), [].methods.include?(as_name(:each))
assert_equal __(true), [].methods.include?(:each)
end

def test_iterating_with_each
Expand Down
2 changes: 1 addition & 1 deletion src/about_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_constants_can_be_looked_up_explicitly
end

def test_you_can_get_a_list_of_constants_for_any_class_or_module
assert_equal __(["Dog"], [:Dog]), Jims.constants
assert_equal __([:Dog]), Jims.constants
assert Object.constants.size > _n_(10)
end
end
21 changes: 4 additions & 17 deletions src/about_strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,12 @@ def test_you_can_get_a_substring_from_a_string

def test_you_can_get_a_single_character_from_a_string
string = "Bacon, lettuce and tomato"
assert_equal __(97, 'a'), string[1]

# Surprised?
end

in_ruby_version("1.8") do
def test_in_older_ruby_single_characters_are_represented_by_integers
assert_equal __(97, 'a'), ?a
assert_equal __(true, false), ?a == 97

assert_equal __(true), ?b == (?a + 1)
end
assert_equal __('a'), string[1]
end

in_ruby_version("1.9", "2", "3", "4") do
def test_in_modern_ruby_single_characters_are_represented_by_strings
assert_equal __('a'), ?a
assert_equal __(false), ?a == 97
end
def test_in_modern_ruby_single_characters_are_represented_by_strings
assert_equal __('a'), ?a
assert_equal __(false), ?a == 97
end

def test_strings_can_be_split
Expand Down
34 changes: 7 additions & 27 deletions src/neo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,19 @@ def before_ruby_version(version)
Gem::Version.new(RUBY_VERSION) < Gem::Version.new(version)
end

in_ruby_version("1.8") do
class KeyError < StandardError
end
end

# Standard, generic replacement value.
# If value19 is given, it is used in place of value for Ruby 1.9.
def __(value="FILL ME IN", value19=:mu)
if RUBY_VERSION < "1.9"
value
else
(value19 == :mu) ? value : value19
end
def __(value="FILL ME IN")
value
end

# Numeric replacement value.
def _n_(value=999999, value19=:mu)
if RUBY_VERSION < "1.9"
value
else
(value19 == :mu) ? value : value19
end
def _n_(value=999999)
value
end

# Error object replacement value.
def ___(value=FillMeInError, value19=:mu)
if RUBY_VERSION < "1.9"
value
else
(value19 == :mu) ? value : value19
end
def ___(value=FillMeInError)
value
end

# Method name replacement.
Expand All @@ -70,9 +52,7 @@ def ____(method=nil)
end
end

in_ruby_version("1.9", "2", "3", "4") do
public :method_missing
end
public :method_missing
end

class String
Expand Down