Skip to content

Instantly share code, notes, and snippets.

@miry
Last active October 27, 2020 13:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miry/f339d0b245a06aa9f0924ad851a463f6 to your computer and use it in GitHub Desktop.
Save miry/f339d0b245a06aa9f0924ad851a463f6 to your computer and use it in GitHub Desktop.
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" }
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