Project

General

Profile

Actions

Feature #11049

closed

Enumerable#grep_v (inversed grep)

Added by sorah (Sorah Fukumori) almost 9 years ago. Updated almost 9 years ago.

Status:
Closed
Target version:
-
[ruby-core:<unknown>]

Description

sometime I want to do grep -v like operation:

%w(aaa bbb ccc).reject { |x| /b/ === x } #=> ["aaa", "ccc"]

We already have Enumerable#grep, so I propose to add Enumerable#grep_v.

%w(aaa bbb ccc).grep(/b/) #=> ["bbb"]
%w(aaa bbb ccc).grep_v(/b/) #=> ["aaa", "ccc"]

Naming / Interface

This idea is mentioned at DevelopersMeeting20150408Japan by me. Matz has said "I don't disagree for the feature. So this remains naming (interface) problem."

I'm not sure grep_v is the best name for this feature; feedback are welcomed.

Ideas

  • grep_v(pattern) (the first patch)
  • grep(pattern, inverse: true)
  • grep!(pattern)

Files

grepv.patch (4.24 KB) grepv.patch sorah (Sorah Fukumori), 04/08/2015 10:23 AM

Related issues 3 (1 open2 closed)

Related to Ruby master - Feature #5588: add negation flag (v) to RegexpClosednaruse (Yui NARUSE)Actions
Related to Ruby master - Feature #9602: Logic with `Enumerable#grep`Feedbackmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #8921: Allow select, reject, etc to accept a regexOpenActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0