Permalink
Browse files

Support to return Enumerator for String#gsub,gsub!

  • Loading branch information...
ksss committed Mar 19, 2017
1 parent 0957492 commit 67a6982710f7538ef1f568fc9e87cfd3c50857c2
Showing with 2 additions and 0 deletions.
  1. +2 −0 mrblib/string.rb
View
@@ -58,6 +58,7 @@ def __sub_replace(pre, m, post)
#
# ISO 15.2.10.5.18
def gsub(*args, &block)
return to_enum(:gsub, *args) if args.length == 1 && !block
if args.size == 2
pattern, replace = *args
plen = pattern.length
@@ -91,6 +92,7 @@ def gsub(*args, &block)
# ISO 15.2.10.5.19
def gsub!(*args, &block)
raise RuntimeError, "can't modify frozen String" if frozen?
return to_enum(:gsub!, *args) if args.length == 1 && !block
str = self.gsub(*args, &block)
return nil if str == self
self.replace(str)

0 comments on commit 67a6982

Please sign in to comment.