Created
June 4, 2012 17:16
-
-
Save Fitzsimmons/2869632 to your computer and use it in GitHub Desktop.
Local Jump Errors
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
class T | |
def initialize(&block) | |
self.class.send(:define_method, :runner, &block) | |
end | |
def do_stuff | |
self.runner do |thing| | |
puts thing | |
end | |
end | |
end | |
t = T.new do | |
yield "hello, " | |
yield "world" | |
end | |
begin | |
t.do_stuff | |
rescue LocalJumpError | |
puts "LocalJumpError caught" | |
end | |
######################################### | |
class P | |
def initialize(runner) | |
@runner = runner | |
end | |
def do_stuff | |
@runner.call do |thing| | |
puts thing | |
end | |
end | |
end | |
l = lambda do | |
yield "proc, " | |
yield "hello" | |
end | |
p = P.new(l) | |
p.do_stuff #Also LocalJumpError, wtf!? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment