Bird
0
0

Identify the problem in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - Enumerable and Collection Processing
Identify the problem in this Ruby code snippet:
arr = [5, 10, 15]
puts arr.any? { |x| x > 20 }
ASyntax error due to missing block
BNo problem, code runs and prints false
Cany? method does not accept blocks
Darr should be a hash for any? to work
Step-by-Step Solution
Solution:
  1. Step 1: Check code syntax and method usage

    The any? method accepts a block and the syntax is correct.
  2. Step 2: Evaluate the condition

    Since no element is greater than 20, any? returns false and prints it.
  3. Final Answer:

    No problem, code runs and prints false -> Option B
  4. Quick Check:

    any? with block returns boolean, no syntax error [OK]
Quick Trick: any? accepts blocks and returns true/false [OK]
Common Mistakes:
  • Assuming syntax error without block
  • Thinking any? does not accept blocks
  • Confusing array with hash requirement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes