Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created January 14, 2013 01:11
Show Gist options
  • Select an option

  • Save jeffreyiacono/4527103 to your computer and use it in GitHub Desktop.

Select an option

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.
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!"
@jeffreyiacono
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment