Skip to content

Instantly share code, notes, and snippets.

@dekart
Created August 21, 2013 11:13
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 dekart/6293194 to your computer and use it in GitHub Desktop.
Save dekart/6293194 to your computer and use it in GitHub Desktop.
class Object
def self.my_decorator(method_name)
alias_method "#{method_name}_without_my_decorator", method_name
define_method method_name do
puts "My decorator logic starts"
result = send("#{method_name}_without_my_decorator")
puts "My decorator logic ends"
result
end
end
end
class MyClass
def hello
puts "Hello world!"
123
end
my_decorator :hello
end
MyClass.new.hello
# My decorator logic starts
# Hello world!
# My decorator logic ends
# => 123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment