Ruby – lambda vs. Proc.new [duplicate]

This is one of the main differences between Procs and lambdas.

A return in a Proc returns from its enclosing block/method, while a return in a lambda simply returns from the lambda. When you call the lambda inside the func_two, it simply returns its value in place, which is not saved.

Read on Procs v. lambdas here:
http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Method_Calls

See duplicate SO question:
Why does explicit return make a difference in a Proc?

EDIT:

To further illustrate this difference, swap func_one and func_two for blocks and see what happens:

> begin; lambda { return 1 }.call end
1
> begin; Proc.new { return 1 }.call end
LocalJumpError: unexpected return
...

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)