If there are 2 modules - module Abc
and module Bcd
and one class - class Efg
.
Now we want to include module Abc
into class Efg
in once instance and need to include module Bcd
into class Efg in another instance but not both modules at same time.
Is it possible to do in Ruby classes?
If I am understanding your question properly then I think you can use singleton_class to include a module only for a specific instance of a class:
Now
inst1
will have the methods fromAsd
andinst2
will have the methods fromBcd
.inst3
will have none of the methods.