Skip to content

Instantly share code, notes, and snippets.

@yaauie
Created June 4, 2015 00:11
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 yaauie/6243052cfba966d8c9cd to your computer and use it in GitHub Desktop.
Save yaauie/6243052cfba966d8c9cd to your computer and use it in GitHub Desktop.
# quick and dirty back-port of Ruby 2.1's Exception#cause
class Exception
def self.new(*args)
allocate.tap do |exception|
exception.send(:initialize, *args)
exception.cause = $!
end
end
# @return [Exception, nil]
attr_accessor :cause
# @return [Array<Exception>]
def causes
return [] unless cause
[cause].concat(cause.causes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment