adopt String#gsub to fixed split behavior

parent 7ce9cc3b
......@@ -28,12 +28,10 @@ class String
#
# ISO 15.2.10.5.18
def gsub(*args, &block)
lc = ''
if args.size == 2
lc = args[1] if self[-1] == args[0]
split(args[0]).join(args[1]) + lc
split(args[0], -1).join(args[1])
elsif args.size == 1 && block
split(args[0]).join(block.call(args[0]))
split(args[0], -1).join(block.call(args[0]))
else
raise ArgumentError, "wrong number of arguments"
end
......
......@@ -205,7 +205,7 @@ assert('String#gsub!', '15.2.10.5.19') do
b = 'abcabc'
b.gsub!('b') { |w| w.capitalize }
a == 'aBcaBc' && b == 'aBcaBc'
a == 'aBcaBc' && b == 'aBcaBc'
end
assert('String#hash', '15.2.10.5.20') do
......
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