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
enum.c
View on GitHub ↗
static VALUE
enum_none(int argc, VALUE *argv, VALUE obj)
{
struct MEMO *memo = MEMO_ENUM_NEW(Qtrue);
WARN_UNUSED_BLOCK(argc);
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(none), (VALUE)memo);
return memo->v1;
}
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