Bird
0
0

Why does a return inside a Proc cause the enclosing method to exit, but inside a lambda it does not?

hard📝 Conceptual Q10 of 15
Ruby - Blocks, Procs, and Lambdas
Why does a return inside a Proc cause the enclosing method to exit, but inside a lambda it does not?
ABecause Proc inherits return behavior from the method context, lambda acts like an independent function
BBecause Proc is implemented as a method, lambda is not
CBecause lambda uses a different syntax for return
DBecause Proc ignores return statements
Step-by-Step Solution
Solution:
  1. Step 1: Understand Proc's return context

    A Proc shares the return context of the method where it is defined, so its return exits that method.
  2. Step 2: Understand lambda's return context

    A lambda behaves like an independent function or method, so its return exits only the lambda block, not the enclosing method.
  3. Final Answer:

    Because Proc inherits return behavior from the method context, lambda acts like an independent function -> Option A
  4. Quick Check:

    Return context difference = B [OK]
Quick Trick: Proc shares method return; lambda acts like function [OK]
Common Mistakes:
  • Thinking syntax difference causes return behavior
  • Assuming Proc ignores return
  • Confusing implementation details

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes