Bird
0
0

What does the Ruby method any? do when called on an array?

easy📝 Conceptual Q1 of 15
Ruby - Enumerable and Collection Processing
What does the Ruby method any? do when called on an array?
AReturns true if no elements meet the condition
BReturns true only if all elements meet the condition
CReturns true if at least one element meets the condition
DReturns the number of elements that meet the condition
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of any?

    The any? method checks if at least one element in the array satisfies the given condition.
  2. Step 2: Compare with other predicates

    Unlike all? which requires all elements to meet the condition, any? returns true if just one element does.
  3. Final Answer:

    Returns true if at least one element meets the condition -> Option C
  4. Quick Check:

    any? = true if any element matches [OK]
Quick Trick: any? checks if at least one element matches condition [OK]
Common Mistakes:
  • Confusing any? with all?
  • Thinking any? counts elements
  • Assuming any? returns false if one element matches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes