Skip to content

Instantly share code, notes, and snippets.

@amclain
Created May 11, 2014 06:11
Show Gist options
  • Save amclain/1c4d9c5e5b022e8c5324 to your computer and use it in GitHub Desktop.
Save amclain/1c4d9c5e5b022e8c5324 to your computer and use it in GitHub Desktop.
class DecoratorExample
# Add functionality to a method.
def self.my_decorator method
imeth = instance_method method
define_method method do |*args, &block|
"does stuff to " +
imeth.bind(self).call(*args, &block)
end
end
# Returns a description of itself.
my_decorator def foo
'the foo method'
end
end
d = DecoratorExample.new
puts d.foo
# => does stuff to the foo method
require 'pry'; binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment