Bird
0
0

What is the main difference between a lambda and a proc in Ruby?

easy📝 Conceptual Q1 of 15
Ruby - Blocks, Procs, and Lambdas
What is the main difference between a lambda and a proc in Ruby?
AA proc checks the number of arguments, a lambda does not.
BA lambda checks the number of arguments, a proc does not.
CBoth lambda and proc behave exactly the same.
DA lambda cannot be called, but a proc can.
Step-by-Step Solution
Solution:
  1. Step 1: Understand argument checking in lambdas and procs

    Lambdas enforce the exact number of arguments passed, raising an error if incorrect. Procs are more lenient and do not strictly check argument count.
  2. Step 2: Compare behavior of lambda and proc

    Since lambdas check arguments strictly and procs do not, this is the key difference.
  3. Final Answer:

    A lambda checks the number of arguments, a proc does not. -> Option B
  4. Quick Check:

    Argument checking = B [OK]
Quick Trick: Lambdas check args strictly; procs are flexible [OK]
Common Mistakes:
  • Thinking both behave the same
  • Believing procs check arguments strictly
  • Confusing callability of lambdas and procs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes