|
|
||
-------------------------------------------------------- Enumerable#all? enum.all? [{|obj| block } ] => true or false ------------------------------------------------------------------------ Passes each element of the collection to the given block. The method returns true if the block never returns false or nil . If the block is not given, Ruby adds an implicit block of {|obj| obj} (that is all? will return true only if none of the collection members are false or nil .) %w{ ant bear cat}.all? {|word| word.length >= 3} #=> true %w{ ant bear cat}.all? {|word| word.length >= 4} #=> false [ nil, true, 99 ].all? #=> false
Enumerable#all? --- all? --- all? {|item| ... } ruby 1.7 feature: すべての要素が真である場合に true を返します。偽である要素が あれば、ただちに false を返します。 ruby 1.8 feature: ブロックを伴う場合は、各要素に対してブロックを評価し、すべての結果 が真である場合に true を返します。ブロックが偽を返した時点で、 ただちに false を返します。 p [1,2,3].all? {|v| v > 0} # => true p [1,2,3].all? {|v| v > 1} # => false