Last active
October 27, 2020 13:14
-
-
Save miry/f339d0b245a06aa9f0924ad851a463f6 to your computer and use it in GitHub Desktop.
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 method_one(&block) | |
puts "method_one" | |
block.call | |
end | |
def method_two(&block) | |
puts "method_two" | |
block.call | |
end | |
def complex(cond, &block) | |
if cond | |
method_one do | |
block.call | |
rescue => e | |
puts e | |
raise | |
end | |
else | |
method_two do | |
block.call | |
rescue => e | |
puts e | |
raise | |
end | |
end | |
end | |
complex(true) { puts "here run"; raise "one" } | |
complex(false) { puts "here run"; raise "two" } | |
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 method_one(&block) | |
puts "method_one" | |
block.call | |
end | |
def method_two(&block) | |
puts "method_two" | |
block.call | |
end | |
def complex(cond, &block) | |
rblock = Proc.new do | |
block.call | |
rescue => e | |
puts e | |
raise | |
end | |
if cond | |
method_one &rblock | |
else | |
method_two &rblock | |
end | |
end | |
complex(true) { puts "here run"; raise "one" } | |
complex(false) { puts "here run"; raise "two" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment