Created
April 12, 2015 07:50
-
-
Save waterlink/31034925e53cc763511d to your computer and use it in GitHub Desktop.
Override default raise behavior
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
class MyStandardError < StandardError; end | |
module Kernel | |
alias_method :__raise__, :raise | |
def raise(*args) | |
return __raise__(MyStandardError) if args.empty? | |
__raise__(*args) | |
end | |
end | |
class Example | |
def without_args | |
raise | |
end | |
def with_args | |
raise RuntimeError, "Hello World" | |
end | |
end | |
# Example.new.with_args #=> RuntimeError: Hello World | |
# Example.new.without_args #=> MyStandardError: MyStandardError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment