I would like to access my subclass using only the name of my module.
module MyModule
class UselessName
include OtherModel
# only self method
def self.x
end
end
# No other class
end
And I would like to write MyModule.x and not MyModule::UselessName.x
I could transform my module in class, but I use RoR Helpers, and I would prefer that MyModule remains a module and not a class.
Is there a way to do this ?
Thanks 😉
OK, let’s split problem into two – getting list of such methods and making proxies in the module.
Getting list might be a little tricky:
Here we start with list of all public class methods and subtract list of all superclass’s public class methods from it.
Now, assuming we know method’s name, we need to make proxy method.
This code will just make equivalent of following definition at runtime.
So let’s put it together in simple function.
So now you’ll just need to call it for needed modules and classes. Note that “destination” module can be different from “source” module owning the class, so you can slurp all methods (given they have different names or you’ll prefix them using class name) to one module. E.g. for your case just make following call.