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

This commit is contained in:
Yukihiro "Matz" Matsumoto
2015-01-19 22:13:34 +09:00
parent d764632f86
commit 8aba34301b
+3
View File
@@ -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(''))