Created
June 27, 2012 14:49
-
-
Save deepak/3004559 to your computer and use it in GitHub Desktop.
thrown error picks message over to_s
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
# message is shown over to_s (not checked for inspect) | |
# when an error is raised | |
class DefaultError < StandardError | |
def message | |
"default-message" | |
end | |
end | |
class SameMessageError < DefaultError | |
end | |
class SpecificError < DefaultError | |
alias :message :to_s | |
end | |
f = SameMessageError.new "specific-message" | |
# raise f #default-message is shown and NOT specific-message | |
f = SpecificError.new "specific-message" | |
raise f #specific-message is shown this time and NOT default-message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment