Created
June 4, 2015 00:11
-
-
Save yaauie/6243052cfba966d8c9cd 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
# 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