Recall & Review
beginner
What is a Proc in Ruby?
A Proc is an object that holds a block of code which can be stored in a variable and called later.
Click to reveal answer
beginner
How do you create a Proc in Ruby?
You create a Proc by using
Proc.new { ... } or the shorthand proc { ... }.Click to reveal answer
beginner
How do you call a Proc once it is created?
You call a Proc using
proc_object.call(arguments).Click to reveal answer
intermediate
What happens if you call a Proc with the wrong number of arguments?
A Proc is flexible and does not raise an error if called with fewer or more arguments than expected. Missing arguments become nil.
Click to reveal answer
intermediate
Difference between Proc and lambda in Ruby?
A Proc is more lenient with arguments and returns from the calling method, while a lambda checks arguments strictly and returns from itself.
Click to reveal answer
How do you create a Proc object in Ruby?
✗ Incorrect
You create a Proc using Proc.new with a block, like Proc.new { puts 'Hello' }.
How do you execute the code inside a Proc named 'p'?
✗ Incorrect
You call a Proc using the call method: p.call().
What happens if you call a Proc with fewer arguments than it expects?
✗ Incorrect
A Proc assigns nil to missing arguments instead of raising an error.
Which of these is true about Procs compared to lambdas?
✗ Incorrect
Procs return from the calling method, unlike lambdas which return from themselves.
Which syntax creates a Proc using shorthand in Ruby?
✗ Incorrect
The shorthand to create a Proc is using proc { ... }.
Explain how to create and call a Proc in Ruby with an example.
Think about how you store a block of code and run it later.
You got /3 concepts.
Describe the difference between a Proc and a lambda in Ruby.
Focus on how they treat arguments and return statements.
You got /3 concepts.