what is the use of Lambda in Ruby??

48 views
Skip to first unread message

Jitendra Sharma

unread,
Dec 14, 2014, 10:40:51 AM12/14/14
to rubyonra...@googlegroups.com
Hi Guys,

i am learning ruby on rails and i am little bit confuse about the use of Lambda.
can anybody help me to understand the use of Lambda?

Dave Aronson

unread,
Dec 14, 2014, 1:23:52 PM12/14/14
to rubyonrails-talk
On Sun, Dec 14, 2014 at 10:40 AM, Jitendra Sharma
<jitendras...@gmail.com> wrote:

> can anybody help me to understand the use of Lambda?

The short version is, it's a way to make an object out of a
method-like chunk of code (including making it take parameters if you
want), so that you can treat it like any other object. You can store
it, copy it, pass it around as a parameter to methods, and execute it
later, possibly many times and with different parameters.

For instance, I recently made a class whose initializer takes a
lambda. Later, when you call certain methods on the objects of this
class, they call the lambda. If you want to see how that works, and
some examples of its usage, see
https://github.com/davearonson/hook_lying_syncer -- though the actual
purpose is to support Ruby "metaprogramming", which is a somewhat
advanced technique.

-Dave

--
Dave Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.
Reply all
Reply to author
Forward
0 new messages