No method_added
hook implementation leads to proper working with include
'ed methods.
Use prepend
from Ruby 2.0. Decorators should return Module
s as results of calling new
:
class Memoize
def self.new(method)
m = Module.new
m.define_method(method) do
# memoization logic goes here.
# use `super` to call original method.
end
m
end
end
Included methods should work fine in my lib (assuming that the decoration was done inside the module itself). Have you run into problems doing that, or are you focused only on the includer itself doing the decoration?
(I really like the simplicity of this version.)