Actions
Feature #9602
closedLogic with `Enumerable#grep`
Feature #9602:
Logic with `Enumerable#grep`
Description
Enumerable#grep is useful to filter things:
[nil, {}, [], 1, :foo, "foo"].grep(String)
# => ["foo"]
-
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 likeEnumerable#grepto 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 afterwhenincasecondition:[nil, {}, [], 1, :foo, "foo"].grep(String, Symbol, Array) # => [[], :foo, "foo"] -
Also, it often happens that I want the negation of grep. Perhaps,
Enumerable#grepv(grepvcomes fromgrep -v) can be implemented as negation ofEnumerable#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
Actions