Complete the code to create a lambda that takes one argument.
my_lambda = [1] do |x| x * 2 end
In Ruby, lambda creates a lambda object that checks the number of arguments (arity).
Complete the code to create a proc that ignores extra arguments.
my_proc = [1] do |x| x + 1 end puts my_proc.call(5, 10)
Using proc creates a proc that does not enforce the number of arguments strictly.
Fix the error in the code by choosing the correct keyword to create a lambda.
my_func = [1] do |x, y| return x + y end puts my_func.call(2, 3)
Only lambda treats return as returning from the lambda itself, not the enclosing method.
Fill both blanks to create a proc and call it with two arguments, ignoring extra ones.
my_proc = [1] do |a, b| a - b end puts my_proc.call(10, 5, [2])
Using proc allows extra arguments to be ignored. The third argument '20' is ignored.
Fill all three blanks to create a lambda, call it with correct arguments, and return the sum.
my_lambda = [1] do |x, y| [2] x + y end result = my_lambda.call([3], 7) puts result
Using lambda with return returns from the lambda itself. Calling with 5 and 7 sums to 12.