String#[]= should support negative position; close #2707

parent d764632f
......@@ -129,6 +129,9 @@ class String
# Modify +self+ by replacing the content of +self+
# at the position +pos+ with +value+.
def []=(pos, value)
if pos < 0
pos += self.length
end
b = self[0, pos]
a = self[pos+1..-1]
self.replace([b, value, a].join(''))
......
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