Feature #11049
closedEnumerable#grep_v (inversed grep)
Description
sometime I want to do grep -v like operation:
We already have Enumerable#grep, so I propose to add Enumerable#grep_v.
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
Updated by recursive-madman (Recursive Madman) about 11 years ago
Updated by Eregon (Benoit Daloze) about 11 years ago
Updated by Eregon (Benoit Daloze) about 11 years ago
grep(pattern, inverse: true) seems the least surprising to me.
But of course it does not buy much compared to #reject.
Updated by recursive-madman (Recursive Madman) about 11 years ago
Benoit Daloze wrote:
That only works for some regexps, I doubt there is a proper and well defined inverted regexp for any Regexp.
Could you provide an example that doesn't work?
Updated by akr (Akira Tanaka) about 11 years ago
Recursive Madman wrote:
Benoit Daloze wrote:
That only works for some regexps, I doubt there is a proper and well defined inverted regexp for any Regexp.
Could you provide an example that doesn't work?
Updated by nobu (Nobuyoshi Nakada) about 11 years ago
invert looks same as my proposal, Regexp#!.
Updated by sawa (Tsuyoshi Sawada) about 11 years ago
How is this proposal different from #9602? I thought that Matz had already suggested to modify select, and Sam Rawlins had implemented select and reject.
Updated by sorah (Sorah Fukumori) about 11 years ago
- Assignee set to matz (Yukihiro Matsumoto)
I didn't know/hear that.
@matz (Yukihiro Matsumoto) what do you think for now?
Updated by akr (Akira Tanaka) about 11 years ago
- Related to Feature #5588: add negation flag (v) to Regexp added
Updated by akr (Akira Tanaka) about 11 years ago
- Related to Feature #9602: Logic with `Enumerable#grep` added
Updated by haraldb (Harald Böttiger) about 11 years ago
Recursive Madman wrote:
How about implementing
Regexp#invertinstead?
As grep using the case statement this would be ignoring a lot of cases that would be handy:
array.invert_grep(Array) # Select all elements that are not arrays.
Updated by matz (Yukihiro Matsumoto) about 11 years ago
grep_v seems OK. Accepted.
Matz.
Updated by sorah (Sorah Fukumori) about 11 years ago
- Status changed from Open to Closed
Thanks, committed at r50491, r50492.
Updated by shyouhei (Shyouhei Urabe) over 10 years ago
- Related to Feature #8921: Allow select, reject, etc to accept a regex added