0
0
Rubyprogramming~20 mins

Any?, all?, none? predicates in Ruby - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Predicate Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of any? with a block
What is the output of this Ruby code?
Ruby
numbers = [1, 3, 5, 7]
result = numbers.any? { |n| n.even? }
puts result
ARuntimeError
Bfalse
Cnil
Dtrue
Attempts:
2 left
💡 Hint
Think about whether any number in the array is even.
Predict Output
intermediate
2:00remaining
Result of all? without a block
What does this Ruby code print?
Ruby
values = [true, 1, 'hello']
puts values.all?
Anil
Bfalse
Ctrue
DArgumentError
Attempts:
2 left
💡 Hint
Without a block, all? checks truthiness of each element.
Predict Output
advanced
2:00remaining
none? with a block returning false
What is the output of this Ruby code?
Ruby
words = ['apple', 'banana', 'cherry']
result = words.none? { |w| w.length > 5 }
puts result
Atrue
Bnil
CTypeError
Dfalse
Attempts:
2 left
💡 Hint
Check if any word has length greater than 5.
🧠 Conceptual
advanced
2:00remaining
Understanding all? with mixed truthy and falsy values
Given the array [nil, true, false], what does all? return when called without a block?
Afalse
Btrue
Cnil
DArgumentError
Attempts:
2 left
💡 Hint
Remember that all? checks truthiness of each element.
Predict Output
expert
3:00remaining
Complex predicate with any?, all?, none?
What is the output of this Ruby code?
Ruby
data = [0, nil, false, '']
result = [
  data.any?,
  data.all?,
  data.none?
]
puts result.inspect
A[true, false, false]
B[false, false, true]
C[true, true, false]
D[false, true, false]
Attempts:
2 left
💡 Hint
Recall that only false and nil are falsy; zero and empty string are truthy.