I read in many textbooks that
In Ruby, a class can only be a subclass of one class. However, mixins allow classes to share methods without a common ancestor.
In practice, when I need to implement multiple inheritance. I use Modules, not mixins. eg:
Module name_goes_here
def method_name_goes_here
.....
end
end
Then I just include them in the class
class MySubClass < MySuperClass
include module_name
end
Now I have mentioned several ruby ββbooks, each one talking about mixins, and then all of a sudden they all start talking about modules, making it clear what the ratio of mixins and modules is.
so, Question: Are the modules == mixins in ruby? if so, why. if not, then what's the difference?
PS: sorry if its a stupid question
source
share