instance method
Enumerable#all?
() -> bool
() { (Elem) -> ::boolish } -> bool
all? → true or false
all?(pattern) → true or false
all? {|element| ... } → true or false
enum.c
View on GitHub ↗
static VALUE
enum_all(int argc, VALUE *argv, VALUE obj)
{
struct MEMO *memo = MEMO_ENUM_NEW(Qtrue);
WARN_UNUSED_BLOCK(argc);
ENUM_BLOCK_CALL(all);
return memo->v1;
}
Returns whether every element meets a given criterion.
If self has no element, returns true and argument or block are not used.
With no argument and no block, returns whether every element is truthy:
Example
(1..4).all? # => true %w[a b c d].all? # => true [1, 2, nil].all? # => false ['a','b', false].all? # => false [].all? # => true
With argument pattern and no block, returns whether for each element element, pattern === element:
Example
(1..4).all?(Integer) # => true (1..4).all?(Numeric) # => true (1..4).all?(Float) # => false %w[bar baz bat bam].all?(/ba/) # => true %w[bar baz bat bam].all?(/bar/) # => false %w[bar baz bat bam].all?('ba') # => false {foo: 0, bar: 1, baz: 2}.all?(Array) # => true {foo: 0, bar: 1, baz: 2}.all?(Hash) # => false [].all?(Integer) # => true
With a block given, returns whether the block returns a truthy value for every element:
Example
(1..4).all? {|element| element < 5 } # => true (1..4).all? {|element| element < 4 } # => false {foo: 0, bar: 1, baz: 2}.all? {|key, value| value < 3 } # => true {foo: 0, bar: 1, baz: 2}.all? {|key, value| value < 2 } # => false