Bird
0
0

What is the issue with this Ruby code?

medium📝 Debug Q6 of 15
Ruby - Functional Patterns in Ruby
What is the issue with this Ruby code?
divide = ->(x, y) { x / y }
curried_divide = divide.curry
result = curried_divide.call(10, 2)
puts result
AIt raises an ArgumentError because too many arguments are passed to curried function
BIt outputs 5 correctly
CIt raises a ZeroDivisionError
DIt outputs 0
Step-by-Step Solution
Solution:
  1. Step 1: Define the lambda

    The lambda divides x by y.
  2. Step 2: Curry the lambda

    Currying expects arguments one at a time.
  3. Step 3: Incorrect call with two arguments

    curried_divide.call(10, 2) passes both arguments at once, which is invalid for curried procs.
  4. Step 4: Correct usage

    Should call as curried_divide.call(10).call(2).
  5. Final Answer:

    It raises an ArgumentError because too many arguments are passed to curried function -> Option A
  6. Quick Check:

    Curried procs accept one argument per call [OK]
Quick Trick: Curried functions require one argument per call [OK]
Common Mistakes:
  • Passing all arguments at once to a curried function
  • Confusing currying with partial application
  • Expecting automatic argument unpacking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes