0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

0
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?