Forum: Ruby Selectively including from a module - is this possible?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2017-01-04 11:21
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?
This topic is locked and can not be replied to.