Issue #17140 has been updated by duerst (Martin D=FCrst).


I guess I understand the first example. Just to make sure:

```
[-3, 4, 0, 8.5, 20, 5].select(1..10) #=3D> [4, 8.5, 5]
```

But for the second example, I don't understand `{ 'and', 'the', 'of' }`. Is=
 that supposed to be an array, or what?

----------------------------------------
Feature #17140: Merge Enumerable#grep(_v) with Enumerable#select/reject
https://bugs.ruby-lang.org/issues/17140#change-87391

* Author: baweaver (Brandon Weaver)
* Status: Open
* Priority: Normal
----------------------------------------
In recent versions of Ruby we've gotten new behavior of some Enumerable met=
hods like any?, all?, none?, one?, and others to support a single argument =
pattern that responds to `=3D=3D=3D`. This is very powerful, and very usefu=
l.

Currently Enumerable has `grep` and `grep_v` which allow this as a way to f=
ilter lists.

These names require some understanding of Unix to be familiar with, but nam=
ing aside, I feel it may make sense to implement `=3D=3D=3D` pattern argume=
nts in `Enumerable#select` and `Enumerable#reject` as with the above.

Proposed Syntax:

```ruby
list_of_numbers.select(1..10)
words.reject({ 'and', 'the', 'of' })
```

I believe this would help with readability and would simplify syntax option=
s by unifying on this standard.

My concern is that `Enumerable#find` already takes a single argument, `ifno=
ne`, and may not be able to implement this behavior. I would be curious to =
see how many use `ifnone` but feel this would be more critically breaking t=
o do.



-- =

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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>