Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean for argument handling to be "rigid"?

Tags:

ruby

Taken from the documentation for Proc#lambda?:

Returns true for a Proc object for which argument handling is rigid. Such procs are typically generated by lambda.

What is "rigid argument" handling?

like image 500
mbigras Avatar asked Dec 18 '25 13:12

mbigras


1 Answers

Lambdas will raise an ArgumentError if passed the wrong number of arguments, Proc.new won't.

Example:

lam = ->(x){ "OK" }
lam.lambda? # => true
lam.call # => ArgumentError
lam.call(1) # => OK

proc = Proc.new { |x| "OK" }
proc.lambda? # => false
proc.call # => OK
proc.call(1) # => OK
proc.call(1,2,3,4,5,6,7,8,9) # => OK
like image 107
max pleaner Avatar answered Dec 21 '25 06:12

max pleaner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!