Skip to content

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

instance method

Enumerable#none?

enum.none? [{ |obj| block }] → true or false
enum.none?(pattern) → true or false

Passes each element of the collection to the given block. The method returns true if the block never returns true for all elements. If the block is not given, none? will return true only if none of the collection members is true.

If instead a pattern is supplied, the method returns whether pattern === element for none of the collection members.

Example
%w{ant bear cat}.none? { |word| word.length == 5 } #=> true
%w{ant bear cat}.none? { |word| word.length >= 4 } #=> false
%w{ant bear cat}.none?(/d/)                        #=> true
[1, 3.14, 42].none?(Float)                         #=> false
[].none?                                           #=> true
[nil].none?                                        #=> true
[nil, false].none?                                 #=> true
[nil, false, true].none?                           #=> false
See also #minmax_by #one? #minmax #partition also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1