Created
August 14, 2011 05:38
-
-
Save luckydev/1144620 to your computer and use it in GitHub Desktop.
Proc and Lambda: Difference 1 - Return policy
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 my_awesome_method | |
ret = lambda { return "This is returned from Lambda" } | |
ret.call | |
"This line will run" | |
end | |
puts my_awesome_method | |
# => "This is returned from Lambda" | |
# => "This line will run" |
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 my_awesome_method | |
ret = Proc.new { return "This is returned from Proc" } | |
ret.call | |
"I won't be executed if Proc is returning above me" | |
end | |
puts my_awesome_method | |
# => "This is returned from Proc" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment