Project

General

Profile

Actions

Feature #11286

closed

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

Added by 0x0dea (D.E. Akers) over 9 years ago. Updated almost 7 years ago.

Status:
Closed
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 2 (1 open1 closed)

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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0