mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-17 07:53:20 -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
|
assert_equal __([]), fido.instance_variables
|
||||||
|
|
||||||
fido.set_name("Fido")
|
fido.set_name("Fido")
|
||||||
assert_equal __(["@name"]), fido.instance_variables
|
assert_equal __(["@name"], [:@name]), fido.instance_variables
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance_variables_cannot_be_accessed_outside_the_class
|
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
|
def test_all_objects_support_to_s_and_inspect
|
||||||
array = [1,2,3]
|
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 __("[1, 2, 3]"), array.inspect
|
||||||
|
|
||||||
assert_equal __("STRING"), "STRING".to_s
|
assert_equal __("STRING"), "STRING".to_s
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class AboutScope < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_you_can_get_a_list_of_constants_for_any_class_or_module
|
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)
|
assert Object.constants.size > _n_(10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -141,17 +141,26 @@ EOS
|
|||||||
|
|
||||||
def test_you_can_get_a_single_character_from_a_string
|
def test_you_can_get_a_single_character_from_a_string
|
||||||
string = "Bacon, lettuce and tomato"
|
string = "Bacon, lettuce and tomato"
|
||||||
assert_equal __(97), string[1]
|
assert_equal __(97, 'a'), string[1]
|
||||||
|
|
||||||
# Surprised?
|
# Surprised?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_single_characters_are_represented_by_integers
|
in_ruby_version("1.8") do
|
||||||
assert_equal __(97), ?a
|
def test_in_ruby_1_8_single_characters_are_represented_by_integers
|
||||||
assert_equal __(true), ?a == 97
|
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
|
||||||
|
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
|
def test_strings_can_be_split
|
||||||
string = "Sausage Egg Cheese"
|
string = "Sausage Egg Cheese"
|
||||||
|
|||||||
@@ -6,12 +6,24 @@ require 'test/unit/assertions'
|
|||||||
class FillMeInError < StandardError
|
class FillMeInError < StandardError
|
||||||
end
|
end
|
||||||
|
|
||||||
def __(value="FILL ME IN")
|
def in_ruby_version(version)
|
||||||
value
|
yield if RUBY_VERSION =~ /^#{version}/
|
||||||
end
|
end
|
||||||
|
|
||||||
def _n_(value=999999)
|
def __(value="FILL ME IN", value19=:mu)
|
||||||
|
if RUBY_VERSION < "1.9"
|
||||||
value
|
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
|
end
|
||||||
|
|
||||||
def ___(value=FillMeInError)
|
def ___(value=FillMeInError)
|
||||||
|
|||||||
Reference in New Issue
Block a user