Project

General

Profile

Actions

Feature #13657

closed

Simplify usage of Enumerable#reject

Added by JustJosh (Joshua Stowers) almost 7 years ago. Updated almost 7 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:81673]

Description

The reject method is more complicated than it has to be when removing only a specific value.
It would be convenient if we could just plug in the value we wish to delete as an optional argument, for example:

[1, 2, 3, 4].reject(3) # => [1, 2, 4]

as apposed to:

[1, 2, 3, 4].reject { |element| element == 3 } # => [1, 2, 4]

The next best method I can think of is #delete, but that returns the value which is deleted.

Updated by shyouhei (Shyouhei Urabe) almost 7 years ago

  • Status changed from Open to Rejected

That's grep_v.

[1, 2, 3, 4].grep_v(3) # => [1, 2, 4]

Updated by JustJosh (Joshua Stowers) almost 7 years ago

Great! You're right, that will accomplish this exactly.

Do you see any hope in adding this functionality to #reject regardless of the existence of #grep_v?
This other method is difficult to make sense of unless the developers are either familiar with it already or have used grep extensively enough to recognize its purpose.

Adding the functionality would also reduce the number of methods developers have to know.
Also it wouldn't hurt to have.

Thanks for pointing out the existence of #grep_v

Updated by shyouhei (Shyouhei Urabe) almost 7 years ago

I guess this request is a variant of https://bugs.ruby-lang.org/issues/11286 (if not identical). You would like to join the thread which is still open, i.e there are chances to introduce your request.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0