Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Blocks, Procs, and Lambdas
What will be the output of this Ruby code?
my_lambda = ->(x) { x + 3 }
puts my_lambda.call(4)
A3
B4
C7
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand the lambda behavior

    The lambda adds 3 to the input number x.
  2. Step 2: Calculate the output

    Calling my_lambda.call(4) computes 4 + 3 = 7.
  3. Final Answer:

    7 -> Option C
  4. Quick Check:

    4 + 3 = 7 [OK]
Quick Trick: Call lambda with .call and input to get output [OK]
Common Mistakes:
  • Forgetting to use .call to invoke lambda
  • Confusing input and output values
  • Expecting syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes