What is lambda?
Try to do this with irb .
lam = lambda { puts "Hello world"} lam.class
lambda in ruby ββis also an instance of the Proc class. lambdas are a different flavor of procs.
What is a Proc?
Proc objects are blocks of code that are bound to a set of local variables.
proc = Proc.new { puts "Hello World" } proc.call
What is the difference between proc and lambda? Comparison will explain usage
Lambdas checks the number of arguments, but procs does not.
multiply = lambda { |x,y| x*y } multiply.call(2,3)
Lambdas and procs treat the return keyword differently (For example, read the article below)
Read this wonderful article for more details http://awaxman11.imtqy.com/blog/2013/08/05/what-is-the-difference-between-a-block/
MadNik Sep 26 '14 at 8:29 2014-09-26 08:29
source share