The recent talk about mixins recently has made me curious. I have a
collection of about 15 mixins that currently get included, in various
combinations, in 5 different classes. Right now, I'm doing something like
this:
class Foo
include M1
include M2
include M3
include M4
end
But it's also possible to do something like this:
class Bar
def initialize
extend M1
extend M2
extend M3
extend M4
end
end
Both solutions seem to work equally well; if I add a new method to M4, for
example, then the method gets added to all existing objects of Foo and
Bar. The first solution seems to be MUCH faster if a lot of objects are
created/destroyed. The second solution seems to be a LITTLE faster if
there is one object, but many calls to methods in M1..M4.
1) Is there any other solution that gives me a better tradeoff in terms of
speed?
2) What are some advantages/disadvantages to each solution that I have
not considered?
Paul