Learn Ruby
Blocks, Procs and Lambda

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.


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.