Bird
0
0

Which Ruby method returns true if at least one element in a collection meets a condition?

easy📝 Conceptual Q11 of 15
Ruby - Enumerable and Collection Processing

Which Ruby method returns true if at least one element in a collection meets a condition?

A<code>all?</code>
B<code>any?</code>
C<code>none?</code>
D<code>each?</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand the meaning of any?

    any? returns true if at least one element satisfies the condition.
  2. Step 2: Compare with other methods

    all? requires all elements to satisfy, none? requires none to satisfy, and each? is not a Ruby predicate method.
  3. Final Answer:

    any? -> Option B
  4. Quick Check:

    any? = at least one true [OK]
Quick Trick: any? means at least one true element [OK]
Common Mistakes:
  • Confusing any? with all?
  • Thinking none? means at least one
  • Using each? which is not a predicate

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes