OK, since the only answer that was appropriate for my question was deleted, I will try to answer my own question based on this deleted answer from @sawa (thanks @sawa for hinting me in the right direction), I changed it a bit to better suit my needs and be more elegant. Later I will describe why @sawa's original answer was not what I was looking for.
Ok, so without further ado, here is my own attempt at a solution:
module Lib module A extend self def foo puts 'Lib::A::foo' end def helper puts 'Lib::A::helper' foo end end module B extend A def self.bar puts 'Lib::B::bar' helper end end end puts 'Calling Lib::A::foo:' Lib::A::foo # => Lib::A::foo puts 'Calling Lib::A::helper:' Lib::A::helper # => Lib::A::helper; Lib::A::foo puts 'Calling Lib::B::bar:' Lib::B::bar # => Lib::B::bar; Lib::A::helper; Lib::A::foo
Here's how it works:
First, he defines all his methods as instance methods of the module class itself ( A in this case). But then, to make them available for external use without creating an instance (which is impossible for modules in the end), I extend module A with myself, which makes these methods also its cool methods. But due to the fact that they are also instances of the method of module A , they can be called from other methods of this module without prefixing them with the name of the module. The same goes for module B , which also extend itself with module A , which makes them their own. Then I can call them inside methods B too, without a prefix, as I wanted.
As you can see, not only can I call the methods of both modules from the outside, as if it were their class methods, and I can call A::helper from B::foo without fully defining its name, but I can also call A::foo from A::helper without qualification. This is exactly what I need and it seems to work the way I expected.
The only problem with this approach may be that their interfaces are mixed. This is not a problem inside B , since this is what I really wanted: to have access to A methods, as if they were methods B , without the need for their prefix with full qualification. So, I have what I deserve. But this can cause the problem from the outside, since it is a part of the implementation of B , which uses the internal methods of A It should not flow into the outside world, but it is. I will try to somehow fix this using access control, perhaps it will be possible.
Edit:. This can be done by inserting the following line immediately after extend A to B :
private_class_method *A.public_instance_methods
This method B can call methods A internally, but they are not accessible from the outside world.
Now what happened to @sawa's original solution:
He used the third module only to proxy the interface through it. For me, this was an ugly hack rather than an elegant solution, because it introduces this add-on module, which confuses users of such a library. They will not know whether they should use A or C , and why such a device is used at all. It is not obvious how this works, just looking at it. He needs a more thorough analysis to find out what he is actually doing and why it is built in this way. This is not a clean design.
In my solution, on the other hand, there are only two modules, as was originally developed, and their purpose should be clear to users of this library. There's this weird extend self , but still it looks like a more common idiom in Ruby than distributing proxy modules all over the place.
So thank you guys for your efforts. Next time try to be less arrogant (when you see that someone asks a question, it’s not always like he is noob) and fixates on your favorite One True Language (don’t get me wrong, I like Ruby, it's pretty cool but it also has some drawbacks, like in any language, and it’s better to look for solutions instead of burying your head and pretending that there are no problems, because this is not what the language was designed for).