Created
January 14, 2013 01:11
-
-
Save jeffreyiacono/4527103 to your computer and use it in GitHub Desktop.
Proc vs lambda: when a return is used inside a proc, it does something called a non-local return — that is, instead of returning from the code executing inside the proc, it returns from its calling context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def return_proc | |
| p = Proc.new { return "Now you see me" } | |
| p.call | |
| return "Now you don't!" | |
| end | |
| return_proc | |
| # => "Now you see me" | |
| def return_lambda | |
| l = lambda { return "Now you see me" } | |
| l.call | |
| return "Now you don't!" | |
| end | |
| return_lambda | |
| # => "Now you don't!" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
via: http://www.dev.gd/20130107-know-your-closures-blocks-procs-and-lambdas.html