为什么带有 splat 参数的 Ruby (2.0) 过程/块的行为与方法和 lambda 不同?
def foo (ids, *args)
p ids
end
foo([1,2,3]) # => [1, 2, 3]
bar = lambda do |ids, *args|
p ids
end
bar.call([1,2,3]) # => [1, 2, 3]
baz = proc do |ids, *args|
p ids
end
baz.call([1,2,3]) # => 1
def qux (ids, *args)
yield ids, *args
end
qux([1,2,3]) { |ids, *args| p ids } # => 1
这是对这种行为的确认,但没有解释: http: //makandracards.com/makandra/20641-careful-when-calling-a-ruby-block-with-an-array