Skip to content

Instantly share code, notes, and snippets.

@noelwarr
Last active August 29, 2015 13:56
Show Gist options
  • Save noelwarr/9275071 to your computer and use it in GitHub Desktop.
Save noelwarr/9275071 to your computer and use it in GitHub Desktop.
Ruby Decorators
class Object
def self.method_added(m)
super(m)
if @wrap_method
@wrap_method = nil
a = "__#{m}__".to_sym
alias_method a, m
define_method(m){
begin
send(a)
rescue => e
puts e.message
puts e.backtrace[3..-1]
end
}
end
end
def self.try_rescue_backtrace
@wrap_method = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment