From 8aba34301b7d81686a70716598b348b554164c29 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 19 Jan 2015 22:13:34 +0900 Subject: String#[]= should support negative position; close #2707 --- mrblib/string.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mrblib/string.rb b/mrblib/string.rb index 66a668e11..1d9ea9e6a 100644 --- a/mrblib/string.rb +++ b/mrblib/string.rb @@ -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('')) -- cgit v1.2.3