Bird
0
0

Which statement correctly describes the difference between a Proc and a lambda in Ruby regarding argument checking?

easy📝 Conceptual Q11 of 15
Ruby - Blocks, Procs, and Lambdas
Which statement correctly describes the difference between a Proc and a lambda in Ruby regarding argument checking?
ABoth <code>Proc</code> and <code>lambda</code> check arguments strictly.
B<code>Proc</code> checks arguments strictly; <code>lambda</code> is lenient.
CNeither <code>Proc</code> nor <code>lambda</code> check arguments.
D<code>Proc</code> is lenient with arguments; <code>lambda</code> checks arguments strictly.
Step-by-Step Solution
Solution:
  1. Step 1: Understand argument checking behavior

    A Proc in Ruby does not enforce the number of arguments strictly; it allows missing or extra arguments without error.
  2. Step 2: Compare with lambda behavior

    A lambda behaves like a method and enforces the exact number of arguments, raising an error if the count is wrong.
  3. Final Answer:

    Proc is lenient with arguments; lambda checks arguments strictly. -> Option D
  4. Quick Check:

    Argument checking = Proc lenient, lambda strict [OK]
Quick Trick: Remember: lambda acts like a method, Proc is more flexible [OK]
Common Mistakes:
  • Thinking both check arguments strictly
  • Confusing which one is strict
  • Assuming Proc raises error on wrong args

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes