def foo
f = Proc.new { return "return from foo from inside proc" }
f.call # control leaves foo here
return "return from foo"
end
def bar
b = Proc.new { "return from bar from inside proc" }
b.call # control leaves bar here
return "return from bar"
end
puts foo # prints "return from foo from inside proc"
puts bar # prints "return from bar"
Ich dachte, die return
Schlüsselwort in Ruby optional war und dass Sie immer return
ob Sie es wünschen oder nicht. Angesichts dessen finde ich es überraschend, dass foo
y bar
haben eine unterschiedliche Leistung, die durch die Tatsache bestimmt wird, dass foo
enthält eine ausdrückliche return
sur Proc f
.
Weiß jemand, warum dies der Fall ist?