Bird
0
0

Find the mistake in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - Functional Patterns in Ruby
Find the mistake in this Ruby code snippet:
sum = ->(a, b, c) { a + b + c }
curried_sum = sum.curry
partial = curried_sum.call(1, 2)
puts partial.call()
Acurried_sum.call(1, 2) returns a number, not a lambda
BCalling partial.call() without argument causes error
Csum lambda has wrong number of parameters
Dcurry method is not defined for lambdas
Step-by-Step Solution
Solution:
  1. Step 1: Analyze partial application

    Calling curried_sum.call(1, 2) returns a new lambda waiting for the last argument.
  2. Step 2: Check the final call

    Calling partial.call() without argument causes an error because one argument is missing.
  3. Final Answer:

    Calling partial.call() without argument causes error -> Option B
  4. Quick Check:

    Missing arguments cause error on call [OK]
Quick Trick: Partial calls must supply all remaining arguments [OK]
Common Mistakes:
  • Assuming curry is undefined for lambdas
  • Thinking partial returns a number immediately
  • Ignoring missing argument error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes