我认为当您在方法中调用 proc 时,proc 的返回值会触发从调用 proc 的 out 块上下文返回。当我打电话时,test(a_block)
我觉得puts "after the block"
不应该执行,因为 proc 有一个返回值。进一步......test(a_block)
并且test(b_block)
行为完全相同。我以为这里应该有区别?
a_block = Proc.new do
puts "in the Proc"
55
end
b_block = lambda do
puts "in the lambda"
66
end
def test(block)
puts "in test"
puts block.call
puts "after the block"
99
end
puts test(a_block)
puts test(b_block)