Project

General

Profile

Actions

Feature #6240

closed

Enumerable#drop with negative argument

Added by marcandre (Marc-Andre Lafortune) almost 12 years ago. Updated about 5 years ago.

Status:
Closed
Target version:
-
[ruby-core:44028]

Description

Currently, Enumerable#drop works only for non-negative arguments.

It could be extended so that negative arguments means dropping from the end:

[:hello, :world].drop(-1) # => [:hello]

This could especially be interesting for Lazy#drop, which would keep a circular buffer of elements before yielding them.

(1..6).lazy.drop(-3).each{|x| puts x} # -> prints 1, 2 and 3

Thoughts?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0