Array#all?

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

all? is an Enumerable method that tests whether every element in a collection matches a given condition. It returns true if all elements satisfy the criteria, otherwise false.

Syntax

array.all? { |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.all? { |n| n > 0 }
# => true (all numbers are positive)

numbers.all? { |n| n < 3 }
# => false (4 and 5 are not less than 3)

Without a block

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

[false, nil].all?
# => true (vacuous truth - no falsy values to contradict)

With pattern matching (Ruby 3.0+)

items = [1, 2, 3]

items.all?(Integer)
# => true (all elements are integers)

Common Patterns

Validation checks

# Check if user input is valid
def valid_input?(answers)
  answers.all? { |a| a[:value].present? }
end

Short-circuit evaluation

all? stops after finding the first failure:

# Efficient: stops at first failing validation
users.all? { |u| validate_user(u) }

Errors

Note the vacuous truth behavior with empty arrays:

[].all?
# => true (this surprises many developers!)

Performance Notes

all? iterates lazily and stops as soon as it finds a falsy result, making it efficient for large datasets.

See Also