Since inheritance and interface both has some problems of their own, high level languages like ruby, python supports a different way for organizing code- Mixin.
The code you have written involves mixin, you can see this as interface with implemented methods.When a class can inherit features from more than one parent class, the class is supposed to show multiple inheritance.
Ruby does not suppoprt mutiple inheritance directly but Ruby Modules have another, wonderful use. At a stroke, they pretty much eliminate the need for multiple inheritance, providing a facility called a mixin.
Mixins give you a wonderfully controlled way of adding functionality to classes. However, their true power comes out when the code in the mixin starts to interact with code in the class that uses it.
say we have a module for debugging. we want to use this in many classes and modules. we can just include this debug module to our classes and all methods for debugging will be added in the code as own method of our class.
see the code bellow:
module Debugger
def log
#do stuff
puts "#{Time.now}: This is a log"
end
end
class C
include Debugger
def initialize
#do stuff
end
def run
#do stuff
log
end
end
c = C.new
c.run
ActiveSupport::Concern
to manage module dependencies. The linked page has some examples/use cases. \$\endgroup\$