LoginSignup
0
0

More than 1 year has passed since last update.

Ruby: lambda, proc, アロー演算子, Proc.newの違い

Posted at

Kernel.#lambdaKernel.#proc はどちらもProcオブジェクトを生成する。どちらなのかは Proc#lambda? で判別できる。

  • lambda
    • メソッドに近い
    • 引数の数が違っているとエラーになる
    • returnでlambda自身を抜ける
    • アロー演算子 -> と同じ
  • proc
    • ブロックに近い
    • 引数の数が違っていてもエラーにならない
    • returnでprocを囲むメソッドを抜ける。proc自身を抜けるにはnextを使う
    • Proc.new と同じ
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0