Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
Ruby - Blocks, Procs, and Lambdas
Identify the error in this code snippet:
my_proc = Proc.new { |x| x * 2 }
puts my_proc.call
AProc.new syntax is incorrect
BMissing argument when calling the Proc
CCannot call Proc with call method
DBlock should not have parameters
Step-by-Step Solution
Solution:
  1. Step 1: Analyze Proc definition and call for errors

    The Proc expects one argument x to multiply by 2. The call is made without any argument, which causes an error because x is missing.
  2. Final Answer:

    Missing argument when calling the Proc -> Option B
  3. Quick Check:

    Proc needs argument when called [OK]
Quick Trick: Always pass required arguments when calling a Proc [OK]
Common Mistakes:
  • Calling Proc without required arguments
  • Thinking Proc.new syntax is wrong
  • Believing call method is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes