When to use mixins in Ruby
- by Gilles
I am wondering when to use mixins? I have read about them. Many authors compare them to interfaces, abstract classes, etc.
Mixins are modules that are mixed-in and modules are a way to group similar methods, constants and classes together.
I have seen examples where a module for math functions is created. It makes sense to group and reuse such functions but should I only mix these in a class if I am faced with an inheritance situation? Should I mix these in anytime I want to use them in a class?
Should they be used exactly like interfaces in other languages or are there other subtleties?