RubyのlambdaとProc.newにおけるreturnの挙動の違い

タグ: ruby / 公開: 2014-03-29

以下のような挙動となる。注意。

def method1
  proc = lambda{
    return "return in lambda"
  }
  proc.call
  return "return in method"
end
p method1() #=> "return in method"

def method2
  proc = Proc.new{
    return "return in proc"
  }
  proc.call
  return "return in method"
end
p method2() #=> "return in proc"

参考

この記事をSNSでシェアする
タイトルとURLをコピーする
または投稿画面を開く
Author
Icon
ぺけみさお / xmisao
プログラマ。
Subscription
Recent articles
Related to ruby