Code Editor
Learn
Blocks, Procs, and Lambdas

The Ruby Lambda

Like procs, lambdas are objects. The similarities don't stop there: with the exception of a bit of syntax and a few behavioral quirks, lambdas are identical to procs.

Check out the code in the editor. See the lambda bit? Typing

lambda { puts "Hello!" }

Is just about the same as

Proc.new { puts "Hello!" }

In the example to the right, when we pass the lambda to lambda_demo, the method calls the lambda and executes its code.

Instructions

Now that you know how blocks and procs work, you should be able to guess what this lambda will puts to the console. Click Run to confirm your suspicions!

Report a Bug
If you see a bug or any other issue with this page, please report it here.