Fixed the corner case bug in `String#{gsub!,sub!}`.

`"a".sub!("a", "a")` should not return `nil`.
parent 54246db0
......@@ -99,7 +99,7 @@ class String
raise FrozenError, "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
return nil unless self.index(args[0])
self.replace(str)
end
......@@ -161,7 +161,7 @@ class String
def sub!(*args, &block)
raise FrozenError, "can't modify frozen String" if frozen?
str = self.sub(*args, &block)
return nil if str == self
return nil unless self.index(args[0])
self.replace(str)
end
......
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