Ruby on Rails Sunday, December 14, 2014

On Sun, Dec 14, 2014 at 10:40 AM, Jitendra Sharma
<jitendrasharma45565@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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHxKQijwjei8gJjgwaU95n7eV%2BBEin8%2BCidO-0tpQX70D4VSXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment