adopt String#gsub to fixed split behavior

parent 7ce9cc3b
...@@ -28,12 +28,10 @@ class String ...@@ -28,12 +28,10 @@ class String
# #
# ISO 15.2.10.5.18 # ISO 15.2.10.5.18
def gsub(*args, &block) def gsub(*args, &block)
lc = ''
if args.size == 2 if args.size == 2
lc = args[1] if self[-1] == args[0] split(args[0], -1).join(args[1])
split(args[0]).join(args[1]) + lc
elsif args.size == 1 && block elsif args.size == 1 && block
split(args[0]).join(block.call(args[0])) split(args[0], -1).join(block.call(args[0]))
else else
raise ArgumentError, "wrong number of arguments" raise ArgumentError, "wrong number of arguments"
end 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