나는 proc을 호출했을 때 proc의 반환 값이 proc를 호출 한 out 블록 컨텍스트로부터 리턴을 트리거 할 것이라고 생각했다. 내가 test(a_block)
라고 부를 때, puts "after the block"
은 proc로부터 리턴 값이 있기 때문에 실행되어서는 안된다. 더 ... test(a_block)
및 test(b_block)
은 완전히 동일하게 동작합니다. 여기에 차이가 있다고 생각했는데?또 다른 proc 대 lambda 토론
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)
넣고 '반환'당신은 차이를 볼 수 있습니다. – megas
가능한 [루비에서 proc와 lambda의 차이점은 무엇입니까?] (http://stackoverflow.com/questions/1740046/whats-the-difference-between-a-proc-and-a-lambda-in -루비) –