Skip to content

Instantly share code, notes, and snippets.

@waterlink
Created April 12, 2015 07:50
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 waterlink/31034925e53cc763511d to your computer and use it in GitHub Desktop.
Save waterlink/31034925e53cc763511d to your computer and use it in GitHub Desktop.
Override default raise behavior
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