Purpose of Modules in Ruby

> Just like PHP language, Ruby doesn’t support multiple inheritance. The workaround is to use Modules.

https://ruby-doc.org/docs/ruby-doc-bundle/ProgrammingRuby/book/tut_modules.html

Sample:

module Americano
    def makeAmericano
        puts "Making Americano Coffee"
    end
end

module Cappuccino
    def makeCappuccino
        puts "Making Cappuccino Coffee"
    end
end

module Espresso
    def makeEspresso
        puts "Making Espresso Coffee"
    end
end

module Frappuccino
    def makeFrappuccino
        puts "Making Frappuccino Coffee"
    end
end

module IcedCoffee
    def makeIcedCoffee
        puts "Making Iced Coffee"
    end
end

module Latte
    def makeLatte
        puts "Making Latte Coffee"
    end
end

module AllInOneCoffee
    class Coffee
        include Americano
        include Cappuccino
        include Espresso
        include Frappuccino
        include IcedCoffee
        include Latte
    end
end

coffee = AllInOneCoffee::Coffee.new
coffee.makeAmericano
coffee.makeCappuccino
coffee.makeEspresso
coffee.makeFrappuccino
coffee.makeIcedCoffee
coffee.makeLatte

Output:

Making Americano Coffee
Making Cappuccino Coffee
Making Espresso Coffee
Making Frappuccino Coffee
Making Iced Coffee
Making Latte Coffee