Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Array#none?

array.none? → true or false
array.none? {|element| ... } → true or false
array.none?(obj) → true or false

Returns true if no element of self meet a given criterion.

With no block given and no argument, returns true if self has no truthy elements, false otherwise:

Example
[nil, false].none? # => true
[nil, 0, false].none? # => false
[].none? # => true

With a block given and no argument, calls the block with each element in self; returns true if the block returns no truthy value, false otherwise:

Example
[0, 1, 2].none? {|element| element > 3 } # => true
[0, 1, 2].none? {|element| element > 1 } # => false

If argument obj is given, returns true if obj.=== no element, false otherwise:

Example
['food', 'drink'].none?(/bar/) # => true
['food', 'drink'].none?(/foo/) # => false
[].none?(/foo/) # => true
[0, 1, 2].none?(3) # => true
[0, 1, 2].none?(1) # => false

Related: Enumerable#none?

See also #minmax #one? #min #pack also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0