Ruby - Module Module Methods

Introduction

In addition to instance methods, a module may also have module methods.

Module methods are prefixed with the name of the module:

def MyModule.lose
    return "hi"
end

You can call a module's module methods just as you would call a class's class methods, using dot notation, like this:

MyModule.lose   #=> "hi"

Modules do not have instances and cannot do inheritance.

Classes can have instances (objects created from the class), superclasses (parents), and subclasses (children).

It is not possible to call an instance method from an instance of a module.

It is impossible to create instances of a module.

Modules are used for namespaces and mixins.

Ruby's mixins provide a way of dealing with the problem of multiple inheritance.

Related Topic