Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Blocks, Procs, and Lambdas
What is the output of this Ruby code?
my_proc = proc { |x| x * 2 }
puts my_proc.call(7)
Anil
B14
CError
D7
Step-by-Step Solution
Solution:
  1. Step 1: Understand the Proc's operation

    The Proc multiplies the input by 2.
  2. Step 2: Calculate the output for input 7

    7 * 2 equals 14, so the output is 14.
  3. Final Answer:

    14 -> Option B
  4. Quick Check:

    Proc call output = 14 [OK]
Quick Trick: Proc runs code with input, here doubling 7 gives 14 [OK]
Common Mistakes:
  • Expecting the input itself as output
  • Thinking Proc returns nil by default
  • Assuming syntax error without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes