Mega Code Archive

 
Categories / Ruby / Method
 

Provide different number of parameters for lambda

l = lambda {|x,y| print x,y } l.call(1,2)     # This works l.call(1)       # Wrong number of arguments l.call(1,2,3)   # Wrong number of arguments l.call([1,2])   # Wrong number of arguments l.call(*[1,2])  # Works: explicit splat to unpack the array