Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Blocks, Procs, and Lambdas
Identify the error in this Ruby code:
3.times { |i| puts i do
  puts "Inside block"
end }
ANo error, code runs fine
BMissing block parameter pipes
CUsing puts inside block is invalid
DMixing curly braces and do..end block syntax incorrectly
Step-by-Step Solution
Solution:
  1. Step 1: Analyze block syntax usage

    The code uses curly braces to start a block but then tries to use do..end inside it, which is invalid syntax.
  2. Step 2: Identify correct block syntax

    Blocks must use either curly braces or do..end, not both mixed together.
  3. Final Answer:

    Mixing curly braces and do..end block syntax incorrectly -> Option D
  4. Quick Check:

    Block syntax mixing error = D [OK]
Quick Trick: Use either {} or do..end for one block, not both [OK]
Common Mistakes:
  • Mixing block syntaxes
  • Assuming puts causes error
  • Ignoring missing pipes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes