summaryrefslogtreecommitdiffhomepage
path: root/mrblib/string.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-09-19 21:51:53 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-09-19 22:01:59 +0900
commite207d5af43e9d6e09679e9aee9bf00a843528e0e (patch)
tree7f83038d199fc076b316d51654819ef6bad5fa78 /mrblib/string.rb
parentc09d250ca148c0efc0167d55885bd20da87b43f7 (diff)
downloadmruby-e207d5af43e9d6e09679e9aee9bf00a843528e0e.tar.gz
mruby-e207d5af43e9d6e09679e9aee9bf00a843528e0e.zip
Remove implicit conversion using `to_str` method.
We have added internal convenience method `__to_str` which does string type check.
Diffstat (limited to 'mrblib/string.rb')
-rw-r--r--mrblib/string.rb11
1 files changed, 5 insertions, 6 deletions
diff --git a/mrblib/string.rb b/mrblib/string.rb
index 07b80b340..397603e9d 100644
--- a/mrblib/string.rb
+++ b/mrblib/string.rb
@@ -12,7 +12,7 @@ class String
def each_line(rs = "\n", &block)
return to_enum(:each_line, rs, &block) unless block
return block.call(self) if rs.nil?
- rs = rs.to_str
+ rs = rs.__to_str
offset = 0
rs_len = rs.length
this = dup
@@ -67,7 +67,7 @@ class String
block = nil
end
if !replace.nil? || !block
- replace = replace.to_str
+ replace = replace.__to_str
end
offset = 0
result = []
@@ -129,12 +129,12 @@ class String
end
pattern, replace = *args
- pattern = pattern.to_str
+ pattern = pattern.__to_str
if args.length == 2 && block
block = nil
end
unless block
- replace = replace.to_str
+ replace = replace.__to_str
end
result = []
this = dup
@@ -245,14 +245,13 @@ class String
##
# ISO 15.2.10.5.3
def =~(re)
- raise TypeError, "type mismatch: String given" if re.respond_to? :to_str
re =~ self
end
##
# ISO 15.2.10.5.27
def match(re, &block)
- if re.respond_to? :to_str
+ if String === re
if Object.const_defined?(:Regexp)
r = Regexp.new(re)
r.match(self, &block)