Bird
0
0

Find the error in this Ruby code:

medium📝 Debug Q7 of 15
Ruby - Enumerable and Collection Processing
Find the error in this Ruby code:
arr = [5, 10, 15]
result = arr.select { n > 5 }
puts result.inspect
ASyntax error due to missing parentheses
Bselect method does not exist for arrays
Cputs cannot print arrays
DBlock variable missing in select block
Step-by-Step Solution
Solution:
  1. Step 1: Check the block syntax in select

    The block uses { n > 5 } but does not declare the block variable |n|.
  2. Step 2: Identify the cause of error

    Without |n|, Ruby does not know what n refers to, causing an error.
  3. Final Answer:

    Block variable missing in select block -> Option D
  4. Quick Check:

    Always declare block variable with |variable| [OK]
Quick Trick: Always include |variable| in select block [OK]
Common Mistakes:
  • Omitting block variable
  • Assuming select is undefined
  • Misunderstanding puts output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes