I have a collection of Mixins (you can call them “features”), organized
as a module:
module RM
module Mix; def foo; puts 555; end; end
module Mux; def bar; puts 666; end; end
end
The intended use is like this:
class MyClass
include RM::Mix # defines instance method foo
end
I have another collection of Mixins, which (currently) consists of all
mixins in the previous collection, plus some more:
module IM
include RM
module Max; def baz; puts 777; end; end
end
If I have a class which is supposed to choose from the IM collection:
class MyOtherClass
include IM::Mix # Also defines method foo
include IM::Mux # This defines method bar
include IM::Max # This defines method baz
end
Since I do a include RM within module IM, everything inside RM also goes
into IM.
Now my problem:
I would like to modify the design so that in IM I include from RM only
the mixin Mix, but not Mux. That is, I would like to selectively import
things from another module. I found two solution for this, but I don’t
like neither very much.
Solution 1:
module IM
module Mix
include RM::Mix
end
module Max; def baz; puts 777; end; end
end
Solution 2:
module RM_public
module Mux; def bar; puts 666; end; end
end
module RM
include RM_public
module Mux; def bar; puts 666; end; end
end
module IM
include RM_public
module Max; def baz; puts 777; end; end
end
Question: Is there an easier way in Ruby, which allows me to selectively
include parts from another module?