Project

General

Profile

Feature #13657

Simplify usage of Enumerable#reject

Added by JustJosh (Joshua Stowers) over 2 years ago. Updated over 2 years ago.

Status:
Rejected
Priority:
Normal
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.

History

Updated by shyouhei (Shyouhei Urabe) over 2 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) over 2 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) over 2 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.

Also available in: Atom PDF