Issue #6727 has been updated by marcandre (Marc-Andre Lafortune).


So Matz will decide one day, then.

Here are further objections in the meantime.

duckinator (Nick Markwell) wrote:
> >    rest = arr.drop(1)
> >    _, *rest = arr
> 
> Those two methods you mentioned "work," but the first isn't very clear on its intent

How is the result of dropping the first element not clear? Drop the first element and give me the rest...

> and the second cannot be used as a statement (which is where I have personally seen [1..-1] used the most).

Since you haven't yet given any real world example, that's possible, but I would guess that many times you will also use the first element of the array, no?

Then that's a good pattern to use. Or `foo = arr.shift`.

> 1. Insure it's a meaningful improvement
>   * Yes, this improvement is discussed in multiple Google search results and has received positive feedback when I mentioned it elsewhere.

It would be interesting to see examples in actual code / gems. In the whole of Rails' code, I found exactly *one* case of `array[1..-1]`

> 2. Think about it
>   * What's a good name? Array#rest

"rest" from what?

>   * What exact arguments does it accept? None.

why not? how about [2..-1]?

>   * What does it return? If the Array is empty, nil, otherwise, a new Array.
> * I did not address the objection of .drop(1), because I had forgotten about it.

Is the distinction between `[].rest == nil` and `[1].rest == []` useful? How/when? In particular, in what kind of case would the *only* difference between `arr.drop(1)` and `arr.rest` be useful?

You would like a new method which does exactly what `drop(1)` does, but with less versatility (no way to do `rest(2)`, say) and with a single difference in the case of an empty array.

>   * I do hope `_, *rest = arr` was purely for demonstrative purposes.

The '_' part was, but not the pattern. When you deal with the first part of the array, the pattern can be very useful.

----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-28008

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/