mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
String#casecmp should be call to_str
when non String object sent And should be raise TypeError when can not responsed to `to_str`
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user