Recall & Review
beginner
What is a lambda in Ruby?
A lambda is a special kind of anonymous function or block that can be stored in a variable and called later. It behaves like a method and can take arguments and return values.
Click to reveal answer
beginner
How do you create a lambda in Ruby?
You can create a lambda using either
lambda { |args| ... } or ->(args) { ... } syntax.Click to reveal answer
intermediate
What happens if you use
return inside a lambda?Using
return inside a lambda exits only from the lambda itself, not from the surrounding method or block.Click to reveal answer
intermediate
How does a lambda differ from a Proc in Ruby?
A lambda checks the number of arguments passed and treats
return differently (returns from lambda only). A Proc does not check arguments strictly and return exits from the enclosing method.Click to reveal answer
beginner
How do you call a lambda stored in a variable?
You call a lambda by using the
.call method on the variable, like my_lambda.call(args).Click to reveal answer
Which syntax creates a lambda in Ruby?
✗ Incorrect
The arrow syntax ->(x) { ... } creates a lambda in Ruby.
What happens if you pass the wrong number of arguments to a lambda?
✗ Incorrect
Lambdas check argument count strictly and raise ArgumentError if it doesn't match.
What does
return inside a lambda do?✗ Incorrect
Return inside a lambda exits only the lambda, not the surrounding method.
How do you execute a lambda stored in variable
f?✗ Incorrect
You call a lambda using the .call method.
Which is true about lambdas compared to Procs?
✗ Incorrect
Lambdas check argument count strictly, Procs do not.
Explain how to create and call a lambda in Ruby, including the syntax options.
Think about the arrow syntax and the lambda keyword.
You got /3 concepts.
Describe the difference in behavior between a lambda and a Proc when using return and argument checking.
Focus on how return and arguments behave differently.
You got /4 concepts.