Created
July 24, 2013 12:55
-
-
Save avsej/6070321 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
class Runner | |
def run(&block) | |
begin | |
instance_exec(&block) | |
@on_success.call if @on_success | |
rescue Exception => ex | |
@on_failure.call(ex) if @on_failure | |
end | |
end | |
def on_success(&block) | |
@on_success = block | |
end | |
def on_failure(&block) | |
@on_failure = block | |
end | |
end | |
obj = Runner.new | |
obj.run do | |
on_success do | |
puts "on success" | |
end | |
on_failure do |ex| | |
puts "on failure #{ex.inspect}" | |
end | |
raise | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment