Recall & Review
beginner
What is a Proc in Ruby?
A Proc is a block of code that can be stored in a variable and called later. It behaves like a method but is more flexible and can be passed around.
Click to reveal answer
intermediate
How does a lambda handle the number of arguments (arity) compared to a Proc?
A lambda checks the number of arguments strictly and raises an error if the count doesn't match. A Proc is more lenient and ignores extra arguments or assigns nil to missing ones.
Click to reveal answer
intermediate
What happens when you use
return inside a lambda vs inside a Proc?Inside a lambda,
return exits only from the lambda itself. Inside a Proc, return exits from the method enclosing the Proc, which can cause unexpected behavior.Click to reveal answer
beginner
Which behaves more like a method: Proc or lambda?
A lambda behaves more like a method because it checks arguments strictly and its
return exits only from itself, not the enclosing method.Click to reveal answer
beginner
How do you create a lambda and a Proc in Ruby?
You create a lambda with
lambda { |args| ... } or ->(args) { ... }. You create a Proc with Proc.new { |args| ... } or proc { |args| ... }.Click to reveal answer
What happens if you pass the wrong number of arguments to a lambda?
✗ Incorrect
A lambda strictly checks the number of arguments and raises an error if they don't match.
What does
return inside a Proc do?✗ Incorrect
A
return inside a Proc exits the method that contains the Proc, not just the Proc itself.Which one behaves more like a method in Ruby?
✗ Incorrect
A lambda behaves more like a method because it checks arguments and handles return differently.
How do you create a lambda in Ruby?
✗ Incorrect
You create a lambda using the keyword
lambda or the arrow syntax ->.If a Proc receives fewer arguments than expected, what happens?
✗ Incorrect
A Proc assigns nil to any missing arguments instead of raising an error.
Explain the differences between Proc and lambda in Ruby regarding argument handling and return behavior.
Think about how each handles wrong number of arguments and where return goes.
You got /3 concepts.
Describe how you create and use a Proc and a lambda in Ruby with examples.
Show simple code snippets and explain behavior.
You got /4 concepts.