diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-01-19 22:13:34 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-01-19 22:13:34 +0900 |
| commit | 8aba34301b7d81686a70716598b348b554164c29 (patch) | |
| tree | 744cb2cdcac7dba8824f732b1ef608ba708e4937 | |
| parent | d764632f8601db38fedef22253607a1c8e60c929 (diff) | |
| download | mruby-8aba34301b7d81686a70716598b348b554164c29.tar.gz mruby-8aba34301b7d81686a70716598b348b554164c29.zip | |
String#[]= should support negative position; close #2707
| -rw-r--r-- | mrblib/string.rb | 3 |
1 files changed, 3 insertions, 0 deletions
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('')) |
