Actions
Feature #9602
closedLogic 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#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 afterwhen
incase
condition:[nil, {}, [], 1, :foo, "foo"].grep(String, Symbol, Array) # => [[], :foo, "foo"]
-
Also, it often happens that I want the negation of grep. Perhaps,
Enumerable#grepv
(grepv
comes 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
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0