Skip to content

Instantly share code, notes, and snippets.

@sugamasao
Created February 6, 2018 15:28
Show Gist options
  • Save sugamasao/6f5b3781c184bc59196f601a505ab073 to your computer and use it in GitHub Desktop.
Save sugamasao/6f5b3781c184bc59196f601a505ab073 to your computer and use it in GitHub Desktop.
each_causeみたいなのがほしい
class StandardError
def each_cause(&block)
e = self
while e
yield e
e = e.cause
end
end
end
begin
raise StandardError, '1st'
rescue => e1
begin
raise StandardError, '2nd'
rescue => e2
e2.each_cause do |ex| # <--- こんな感じ
puts ex.message
end
end
end
# % ruby each_cause_sample.rb
# 2nd
# 1st
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment