Issue #9602 has been updated by msnm (Masahiro Nomoto).
I agree with sawa's opinion. `Enumerable#grep` and other methods using `===` internally should accept more than one arguments, following `when` conditions.
Yukihiro Matsumoto wrote:
> We should use #select for more complex filtering.
`#select` is highly versatile. I think it's good that there is a filter method that has the ability between (current) `#grep` and `#select`.
----------------------------------------
Feature #9602: Logic with `Enumerable#grep`
https://bugs.ruby-lang.org/issues/9602#change-82896
* Author: sawa (Tsuyoshi Sawada)
* Status: Feedback
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
`Enumerable#grep` is useful to filter things:
[nil, {}, [], 1, :foo, "foo"].grep(String)
# => ["foo"]
1. Often, the condition cannot be expressed as a single object on which `===` is applied, but as a disjunction over `===` applied to multiple objects. I would like `Enumerable#grep` to take arbitrary number of arguments, and when they are more than one, a logical disjunction applies, just as when there are multiple comma-separated objects after `when` in `case` condition:
[nil, {}, [], 1, :foo, "foo"].grep(String, Symbol, Array)
# => [[], :foo, "foo"]
2. Also, it often happens that I want the negation of grep. Perhaps, `Enumerable#grepv` (`grepv` comes from `grep -v`) can be implemented as negation of `Enumerable#grep`, i.e., select elements for which `===` returns false on any of the arguments:
[nil, {}, [], 1, :foo, "foo"].grepv(String, Symbol, Array)
# => [nil, {}, 1]
---Files--------------------------------
select-to-accept-args.patch (2.62 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.