Skip to content

Instantly share code, notes, and snippets.

@jrochkind
Created August 25, 2016 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrochkind/2f01ea0c8472af63ebf3da365b0852ff to your computer and use it in GitHub Desktop.
Save jrochkind/2f01ea0c8472af63ebf3da365b0852ff to your computer and use it in GitHub Desktop.
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