Project

General

Profile

Actions

Feature #17333

open

Enumerable#many?

Added by okuramasafumi (Masafumi OKURA) about 4 years ago. Updated almost 4 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:100930]

Description

Enumerable#many? method is implemented in ActiveSupport.
https://api.rubyonrails.org/classes/Enumerable.html#method-i-many-3F
However, it's slightly different from Ruby's core methods such as one? or all?, where they take pattern argument.
I believe these methods should behave the same so that it's easier to guess and learn.

We already have none?, one?, any? and all?, which translate into == 0, == 1, > 0 and == self.size.
many? method translates into > 1, which is reasonable to exist.
Currently we need to write something this:

[1, 2, 3].count(&:odd?) > 1

With many?, we can make it simpler:

[1, 2, 3].many?(&:odd?)

Pull Request on GitHub is available at https://github.com/ruby/ruby/pull/3785

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0