Unverified Commit 67a69827 authored by ksss's avatar ksss

Support to return Enumerator for String#gsub,gsub!

parent 09574922
...@@ -58,6 +58,7 @@ class String ...@@ -58,6 +58,7 @@ class String
# #
# ISO 15.2.10.5.18 # ISO 15.2.10.5.18
def gsub(*args, &block) def gsub(*args, &block)
return to_enum(:gsub, *args) if args.length == 1 && !block
if args.size == 2 if args.size == 2
pattern, replace = *args pattern, replace = *args
plen = pattern.length plen = pattern.length
...@@ -91,6 +92,7 @@ class String ...@@ -91,6 +92,7 @@ class String
# ISO 15.2.10.5.19 # ISO 15.2.10.5.19
def gsub!(*args, &block) def gsub!(*args, &block)
raise RuntimeError, "can't modify frozen String" if frozen? raise RuntimeError, "can't modify frozen String" if frozen?
return to_enum(:gsub!, *args) if args.length == 1 && !block
str = self.gsub(*args, &block) str = self.gsub(*args, &block)
return nil if str == self return nil if str == self
self.replace(str) self.replace(str)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment