string type check based on #to_str to encourage duck typing; #1616

This commit is contained in:
Yukihiro "Matz" Matsumoto
2013-12-24 07:02:37 +09:00
parent d957a67841
commit 4d92d2e1aa
+1 -1
View File
@@ -137,7 +137,7 @@ class String
##
# ISO 15.2.10.5.5
def =~(re)
if re.is_a? String
if re.respond_to? :to_str
raise TypeError, "type mismatch: String given"
end
re =~ self