このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ

Ruby 3.0 リファレンスマニュアル

instance method Enumerable#none?

none? -> bool[permalink][rdoc][edit]
none? {|obj| ... } -> bool
none?(pattern) -> bool

ブロックを指定しない場合は、 Enumerable オブジェクトのすべての要素が偽であれば真を返します。そうでなければ偽を返します。

ブロックを指定した場合は、Enumerable オブジェクトのすべての要素をブロックで評価した結果が、すべて偽であれば真を返します。そうでなければ偽を返します。

自身に要素が存在しない場合は true を返します。

[PARAM] pattern:
ブロックの代わりに各要素に対して pattern === item を評価します。

require 'set'
p Set['ant', 'bear', 'cat'].none? {|word| word.length == 5}  # => true
p Set['ant', 'bear', 'cat'].none? {|word| word.length >= 4}  # => false
p Set['ant', 'bear', 'cat'].none?(/d/)                     # => true
p Set[].none?                                              # => true
p Set[nil].none?                                           # => true
p Set[nil,false].none?                                     # => true
p Set[nil, false, true].none?                              # => false

[SEE_ALSO] Array#none?