I have a module that add class methods when included into a class.
I would like to force this module to extend new methods by writing another module that will be included by the first one.
The following code gives an example of what i want to do that does not work :
It would be great to be able to override the “self.included” function of the first module to extend the base with my methods.
So far I was able to override the self.included function of the first module but calling super does not work so I loose the class methods of the first module :
module SomeModule
def self.included(base)
base.send(:extend, ClassMethods)
end
module ClassMethods
# Some methods
end
end
module MyNewModule
def self.included(base)
base.class_eval do
def self.included(base)
base.send(:extend, ClassMethods)
super(base)
end
end
end
module ClassMethods
def my_method
end
end
end
SomeModule.send(:include, MyNewModule)
class Pouet
include SomeModule
my_method # undefined local variable or method `my_method' for Pouet:Class (NameError)
end
Is this possible?
Finally managed to make it work by myself.
Please tell me if this is a good or a bad practice :