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"
I thought the return
keyword was optional in Ruby and that you are always return
ing whether you request it or not. Given that, I find it surprising that foo
and bar
have different output determined by the fact that foo
contains an explicit return
in Proc f
.
Does anyone know why this is the case?