Merge pull request #2088 from ksss/string-casecmp

String#casecmp should be call `to_str`
This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-04-20 21:30:16 +09:00
2 changed files with 8 additions and 1 deletions
+3 -1
View File
@@ -47,7 +47,9 @@ class String
# "abcdef".casecmp("ABCDEF") #=> 0
#
def casecmp(str)
self.downcase <=> str.downcase
self.downcase <=> str.to_str.downcase
rescue NoMethodError
raise TypeError, "no implicit conversion of #{str.class} into String"
end
def partition(sep)
+5
View File
@@ -98,6 +98,11 @@ assert('String#casecmp') do
assert_equal 0, "aBcDeF".casecmp("abcdef")
assert_equal(-1, "abcdef".casecmp("abcdefg"))
assert_equal 0, "abcdef".casecmp("ABCDEF")
o = Object.new
def o.to_str
"ABCDEF"
end
assert_equal 0, "abcdef".casecmp(o)
end
assert('String#start_with?') do