Project Ramon

A learning journey from a Ruby noob perspective

Procs & Lambdas pt.2


In the last post I shared a bit of my understanding of what a Proc is. An anonymous block of code that can be represented as an object and invoked at will.

There are a lot of similarities when using Procs and Lambdas, in fact I’ve read that a lambda is just a particular type of Proc.

As shown below, setting up a lambda is included in the list of similarities:

Their are a few small but important differences I learned about between Procs and lambdas. The first being that when a Proc returns, it does so immediately, without returning to the calling method. lambdas on the other hand, will return control to the corresponding method. Another difference is that a lambda is particular about the number of parameters being passed to it.

This example comes  from p. 417 of The Well Grounded Rubyist:

And that wraps up my elementary understanding of Procs and lambdas. If you have anything to add to this or any other posts, feel free to drop a line or more in the comments.


Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s