End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Enumerable#any?
any? → true or false
any?(pattern) → true or false
any? {|element| ... } → true or false
enum.c
View on GitHub ↗
static VALUE
enum_any(int argc, VALUE *argv, VALUE obj)
{
struct MEMO *memo = MEMO_ENUM_NEW(Qfalse);
WARN_UNUSED_BLOCK(argc);
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(any), (VALUE)memo);
return memo->v1;
}
Returns whether any element meets a given criterion.
With no argument and no block, returns whether any element is truthy:
Example
(1..4).any? # => true %w[a b c d].any? # => true [1, false, nil].any? # => true [].any? # => false
With argument pattern and no block, returns whether for any element element, pattern === element:
Example
[nil, false, 0].any?(Integer) # => true [nil, false, 0].any?(Numeric) # => true [nil, false, 0].any?(Float) # => false %w[bar baz bat bam].any?(/m/) # => true %w[bar baz bat bam].any?(/foo/) # => false %w[bar baz bat bam].any?('ba') # => false {foo: 0, bar: 1, baz: 2}.any?(Array) # => true {foo: 0, bar: 1, baz: 2}.any?(Hash) # => false [].any?(Integer) # => false
With a block given, returns whether the block returns a truthy value for any element:
Example
(1..4).any? {|element| element < 2 } # => true (1..4).any? {|element| element < 1 } # => false {foo: 0, bar: 1, baz: 2}.any? {|key, value| value < 1 } # => true {foo: 0, bar: 1, baz: 2}.any? {|key, value| value < 0 } # => false