Skip to content

Instantly share code, notes, and snippets.

@rstacruz
Forked from sinefunc/pcall.rb
Created May 26, 2010 09:15
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 rstacruz/414262 to your computer and use it in GitHub Desktop.
Save rstacruz/414262 to your computer and use it in GitHub Desktop.
def pcall(object, meth, &blk)
begin
object.send meth
rescue
return if exception.nil?
raise blk.call
end
end
# pcall(obj, :my_method)
# pcall(obj, :my_method) { SomeException.new("my_method has failed") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment