Warum macht die explizite Rückgabe in einem Proc einen Unterschied?

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 dasreturn Das Schlüsselwort war in Ruby optional und das sind Sie immerreturnob Sie es wünschen oder nicht. Angesichts dessen finde ich es überraschend, dassfoo undbar haben unterschiedliche Leistung durch die Tatsache, dass bestimmtfoo enthält eine explizitereturn imProc f.

Weiß jemand, warum das so ist?

Antworten auf die Frage(3)

Ihre Antwort auf die Frage