Learn Ruby
Blocks, Procs and Lambda
25.5
Lesson
Proc & Lambda
The proc
keyword defines a block.
In this way we can store the block in a variable.
Later we can call that block using method call
.
procs can also take arguments.
Lambdas
Ruby also has keyword lambda
which is very similar to proc
.
lambda
enforces arity. It means if a lambda accepts 2 arguments and
if we pass 3 arguments then lambda will raise an error. In such
cases proc
will ignore the extra argument.