Say I have a generic one Proc, Lambdaor methodone that takes an optional second argument:
pow = -> (base, exp: 2) { base**exp }
Now I want to perform this function by providing it with expof 3.
cube = pow.curry.call(exp: 3)
There is an ambiguity that arises because of keyword arguments and the new hash syntax, where Ruby interprets exp: 3as a hash passed as the first argument base. This causes the function to be called immediately, showing NoMethodErrorwhen it is #**sent to the hash.
Setting the default value for the first argument in the same way will cause the function to be called immediately upon currying, and if I mark the first argument if necessary, without specifying the default:
pow = -> (base:, exp: 2) { base**exp }
the interpreter will complain that I am missing an argument basewhen I try to curry Proc.
How can I execute a function with a second argument?
source
share