Array#any?

arr.any? { |element| block } -> true or false
Returns: boolean · Updated March 13, 2026 · Array Methods
arrays enumerable conditionals checking

any? is an Enumerable method that tests whether any element in a collection matches a given condition. It evaluates each element and returns true if at least one element satisfies the criteria, otherwise false.

Syntax

array.any? { |element| block }

Without a block, it checks for truthy values.

Parameters

ParameterTypeDefaultDescription
blockProcA condition to evaluate against each element

Examples

Basic usage

numbers = [1, 2, 3, 4, 5]

numbers.any? { |n| n > 3 }
# => true (because 4 and 5 are greater than 3)

numbers.any? { |n| n > 10 }
# => false

Without a block

[1, 2, 3].any?
# => true (has truthy values)

[false, nil, 0].any?
# => true (0 is truthy!)

[false, nil].any?
# => false

With pattern matching (Ruby 3.0+)

items = [1, "hello", :symbol, 3.14]

items.any?(String)
# => true (has String values)

items.any?(Integer)
# => true (has Integer values)

Common Patterns

Validation checks

# Check if any field changed
def any_changed?(attributes)
  attributes.any? { |_, v| v_changed?(v) }
end

Short-circuit evaluation

any? stops after finding the first truthy result, making it efficient:

# Efficient: stops at first expensive operation
results.any? { |item| process_expensive(item) }

Errors

The method rarely raises exceptions. Note that an empty array returns false:

[].any?
# => false (not nil!)

Performance Notes

any? iterates lazily and stops as soon as it finds a truthy result, making it extremely efficient for large datasets.

See Also