1. In proc and lambda, the return keyword has different meanings :
In proc, return only means returning from this lambda.
In a lambda, return is not returned from the proc, but rather from the scope in which the proc is defined.
Copy Code code as follows:
def One_method
p = Proc.new{return #调用这个块的时候, returns 10 directly from the scope of P, so the following return will not execute
result = P.call
return result * 2
End
def Two_method
p = Lambda{return #调用这个块的时候, returning 10 from the lambda
result = P.call
return result * 2 #继续执行
End
Puts One_method # 10
Puts Two_method # 20
2, in proc and lambda, check the parameters in different ways :
In proc, if the parameter is more than defined, the redundant parameter is ignored, and if the parameter is less than defined, the parameter not passed over is automatically specified as nil.
In a lambda, a argumenterror error is thrown regardless of whether the actual argument is more or less than the defined parameter.