Proc.arity vs Lambda.arity

后端 未结 3 1034
小蘑菇
小蘑菇 2021-02-19 08:22

Why do proc and lambda return different values for arity?

e.g.

proc   { |x = 0| }.arity       #=> 0
lambda { |a = 0| }.arity       #=> -1
proc   {         


        
3条回答
  •  囚心锁ツ
    2021-02-19 09:09

    As mentioned here:(Differences between Proc and Lambda), one of the primary differences between procs and lambda are that "Just like methods, lambdas have strict argument checking, whereas non-lambda Procs have loose argument checking, just like blocks."

    Thus, since the arity is based on the number of required arguments, this will change between procs and lambdas.

提交回复
热议问题