Is this a bad idea?
module Decorate
def decorate(definition, options)
self.send(:alias_method, "__original_#{definition}", definition)
define_method definition, Proc.new { |*args|
send(options.fetch(:with), *args, &Proc.new { |args|
send("__original_#{definition}", *args)
})
}
end
end
Object.include Decorate
class A
class B
def double(a)
a * 2
end
def around(a)
# do stuff before
yield(a)
# do stuff after
end
decorate :double, with: :around
end
end
a = A::B.new
p a.double(100)