mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Answers now Ruby 1.9 compliant
This commit is contained in:
@@ -22,7 +22,7 @@ class AboutClasses < EdgeCase::Koan
|
||||
assert_equal __([]), fido.instance_variables
|
||||
|
||||
fido.set_name("Fido")
|
||||
assert_equal __(["@name"]), fido.instance_variables
|
||||
assert_equal __(["@name"], [:@name]), fido.instance_variables
|
||||
end
|
||||
|
||||
def test_instance_variables_cannot_be_accessed_outside_the_class
|
||||
@@ -180,7 +180,7 @@ class AboutClasses < EdgeCase::Koan
|
||||
def test_all_objects_support_to_s_and_inspect
|
||||
array = [1,2,3]
|
||||
|
||||
assert_equal __("123"), array.to_s
|
||||
assert_equal __("123", "[1, 2, 3]"), array.to_s
|
||||
assert_equal __("[1, 2, 3]"), array.inspect
|
||||
|
||||
assert_equal __("STRING"), "STRING".to_s
|
||||
|
||||
@@ -73,7 +73,7 @@ class AboutScope < EdgeCase::Koan
|
||||
end
|
||||
|
||||
def test_you_can_get_a_list_of_constants_for_any_class_or_module
|
||||
assert_equal __(["Dog"]), Jims.constants
|
||||
assert_equal __(["Dog"], [:Dog]), Jims.constants
|
||||
assert Object.constants.size > _n_(10)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -141,16 +141,25 @@ EOS
|
||||
|
||||
def test_you_can_get_a_single_character_from_a_string
|
||||
string = "Bacon, lettuce and tomato"
|
||||
assert_equal __(97), string[1]
|
||||
assert_equal __(97, 'a'), string[1]
|
||||
|
||||
# Surprised?
|
||||
end
|
||||
|
||||
def test_single_characters_are_represented_by_integers
|
||||
assert_equal __(97), ?a
|
||||
assert_equal __(true), ?a == 97
|
||||
in_ruby_version("1.8") do
|
||||
def test_in_ruby_1_8_single_characters_are_represented_by_integers
|
||||
assert_equal __(97, 'a'), ?a
|
||||
assert_equal __(true, false), ?a == 97
|
||||
|
||||
assert_equal __(true), ?b == (?a + 1)
|
||||
assert_equal __(true), ?b == (?a + 1)
|
||||
end
|
||||
end
|
||||
|
||||
in_ruby_version("1.9") do
|
||||
def test_in_ruby_1_8_single_characters_are_represented_by_strings
|
||||
assert_equal __('a'), ?a
|
||||
assert_equal __(false), ?a == 97
|
||||
end
|
||||
end
|
||||
|
||||
def test_strings_can_be_split
|
||||
|
||||
@@ -6,12 +6,24 @@ require 'test/unit/assertions'
|
||||
class FillMeInError < StandardError
|
||||
end
|
||||
|
||||
def __(value="FILL ME IN")
|
||||
value
|
||||
def in_ruby_version(version)
|
||||
yield if RUBY_VERSION =~ /^#{version}/
|
||||
end
|
||||
|
||||
def _n_(value=999999)
|
||||
value
|
||||
def __(value="FILL ME IN", value19=:mu)
|
||||
if RUBY_VERSION < "1.9"
|
||||
value
|
||||
else
|
||||
(value19 == :mu) ? value : value19
|
||||
end
|
||||
end
|
||||
|
||||
def _n_(value=999999, value19=:mu)
|
||||
if RUBY_VERSION < "1.9"
|
||||
value
|
||||
else
|
||||
(value19 == :mu) ? value : value19
|
||||
end
|
||||
end
|
||||
|
||||
def ___(value=FillMeInError)
|
||||
|
||||
Reference in New Issue
Block a user