Created
August 25, 2016 01:48
-
-
Save jrochkind/2f01ea0c8472af63ebf3da365b0852ff to your computer and use it in GitHub Desktop.
This file contains 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_method | |
yield | |
"method" | |
end | |
my_method { return 'block' } | |
# => raises `LocalJumpError: unexpected return` | |
def my_method(proc_argument) | |
proc_argument.call | |
"method" | |
end | |
my_method(Proc.new { return 'block' }) | |
# => still raises `LocalJumpError: unexpected return`! | |
def proc_method | |
Proc.new { return 'proc' }.call | |
puts 'method' | |
end | |
proc_method | |
# => returns 'proc', `puts 'method'` is never called | |
def my_method | |
yield | |
puts 'after yield' | |
end | |
def calling_method | |
my_method { return "returned early" } | |
puts "after the call of my_method" | |
end | |
x = calling_method | |
# => x is set to 'returned early', neither of of the `puts` statements | |
# execute and print anything to console, because it returned early | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment