numbers = [1, 3, 5, 7] result = numbers.any? { |n| n.even? } puts result
The any? method returns true if at least one element satisfies the block condition. Here, none are even, so it returns false.
values = [true, 1, 'hello'] puts values.all?
The all? method without a block returns true if all elements are truthy. Here, all elements are truthy, so it prints true.
words = ['apple', 'banana', 'cherry'] result = words.none? { |w| w.length > 5 } puts result
The none? method returns true if no elements satisfy the block. Here, 'banana' and 'cherry' have length > 5, so none? returns false.
[nil, true, false], what does all? return when called without a block?all? checks truthiness of each element.Since nil and false are falsy in Ruby, all? returns false when called without a block.
data = [0, nil, false, ''] result = [ data.any?, data.all?, data.none? ] puts result.inspect
false and nil are falsy; zero and empty string are truthy.any? returns true because 0 and '' are truthy.all? returns false because nil and false are falsy.none? returns false because there are truthy elements (0 and '').
