【发布时间】:2011-12-04 17:45:24
【问题描述】:
我认为当您在方法中调用 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)
【问题讨论】:
-
把'return'放在每个块中,你就会看到不同。
标签: ruby lambda proc-object