method
lambda
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
lambda()
public
Equivalent to Proc.new, except the resulting Proc objects check the number of parameters passed when called.
Register or
log in
to add new notes.
x2es -
October 6, 2011
szeryf -
July 16, 2009
![Default_avatar_30](https://www.gravatar.com/avatar/9825be25f35a1eb7d13a873b661709f2?default=http://apidock.com/images/default_avatar_30.png&size=30)
1 thank
Difference in the way returns are handled
Also, there is a difference in the way returns are handled from the Proc. A return from Proc.new returns from the enclosing method. Return in lambda-block acts like in regular method.
return example
def proc_return Proc.new { return "Proc.new"}.call return "proc_return method finished" end def lambda_return lambda { return "lambda" }.call return "lambda_return method finished" end puts proc_return puts lambda_return # => Proc.new # => lambda_return method finished
![Default_avatar_30](https://www.gravatar.com/avatar/024f6d59fd34ceca04f3fc18a87bdb98?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Usage example
Usage example:
cube = lambda {|x| x * x * x } cube.call(3) # => 27 cube.call(6) # => 216