Project

General

Profile

Feature #11286

[PATCH] Add case equality arity to Enumerable's sequence predicates.

Added by 0x0dea (D.E. Akers) over 5 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:69675]

Description

Proposal

It is proposed that Enumerable's sequence predicates (#all?, #any?, #none?, and #one?) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's #=== method.

Rationale

Enumerable#grep filters by case equality, allowing us to write very natural and expressive code:

strs.select { |str| /foo/ === str }
strs.grep(/foo/)

nums.select { |num| (5..10) === num }
nums.grep(5..10)

In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. #grep is a very nice method! Let's make #all? and friends more like #grep.


Files


Related issues

Related to Ruby master - Feature #13067: TrueClass,FalseClass to provide `===` to match truthy/falsy values.Closedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #14197: `Enumerable#{select,reject}` accept a pattern argumentOpenActions

Also available in: Atom PDF