From: matz@... Date: 2019-07-11T05:35:48+00:00 Subject: [ruby-core:93664] [Ruby master Feature#15950] Allow negative length in `Array#[]`, `Array#[]=`, `Array#slice`, `Array#slice!`, `String#[]`, `String#[]=`, `String#slice`, `String#slice!` Issue #15950 has been updated by matz (Yukihiro Matsumoto). I don't see any rational use of this proposal. Rejection confirmed. Matz. ---------------------------------------- Feature #15950: Allow negative length in `Array#[]`, `Array#[]=`, `Array#slice`, `Array#slice!`, `String#[]`, `String#[]=`, `String#slice`, `String#slice!` https://bugs.ruby-lang.org/issues/15950#change-79276 * Author: sawa (Tsuyoshi Sawada) * Status: Rejected * Priority: Normal * Assignee: * Target version: ---------------------------------------- To take the first n characters of a string, using `[]` is straightforward: ```ruby "abcdefgh"[0, 3] # => "abc" ``` But to take the last n characters, we need to use n in two arguments: in the index (in negative form) in addition to the length: ```ruby "abcdefgh"[-3, 3] # => "fgh" ``` This is cumbersome. I wish negative length to be allowed, and be interpreted as measuring leftward (while cycling the receiver if necessary). ```ruby "abcdefgh"[0, -3] # => "fgh" "abcdefgh"[5, -3] # => "cde" ``` If there is not enough characters or elements, it should stop at the boundary. ```ruby "abcdefgh"[1, -3] # => "a" ``` -- https://bugs.ruby-lang.org/ Unsubscribe: