Bird
0
0

What will this code print?

medium📝 Predict Output Q5 of 15
Ruby - Blocks, Procs, and Lambdas
What will this code print?
my_proc = proc { |x, y| x + y }
puts my_proc.call(3, 4)
A7
B34
CError: wrong number of arguments
Dnil
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the Proc parameters and operation

    The Proc takes two arguments and adds them.
  2. Step 2: Add the arguments 3 and 4

    3 + 4 equals 7, so the output is 7.
  3. Final Answer:

    7 -> Option A
  4. Quick Check:

    Proc sum output = 7 [OK]
Quick Trick: Proc parameters match call arguments for correct output [OK]
Common Mistakes:
  • Concatenating numbers as strings
  • Expecting argument error incorrectly
  • Assuming nil output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes