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"
Ruby ではキーワードはオプションであり、要求するかどうかに関係なくreturn
常に ing していると思いました。それを考えると、明示的なinを含むという事実によって決定される と の出力が異なることreturn
は驚くべきことです。foo
bar
foo
return
Proc f
なぜこれが事実なのか誰にも分かりますか?