gpt4 book ai didi

ruby - 参数处理为 "rigid"是什么意思?

转载 作者:数据小太阳 更新时间:2023-10-29 07:47:31 29 4
gpt4 key购买 nike

取自documentation对于 Proc#lambda?:

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

什么是“刚性参数”处理?

最佳答案

如果传递了错误数量的参数,Lambdas 将引发一个 ArgumentError,而 Proc.new 则不会。

例子:

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

关于ruby - 参数处理为 "rigid"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41388995/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com