Ruby Class vs Module
Since a module cannot be instantiated, there is no way for its methods to be called directly. Instead, it should be included in another class, which makes its methods available for use in instances of that class.
Here are the quick pointers of exact difference between a class and module.
Class | Module | |
---|---|---|
instantiation | can be instantiated | can not be instantiated |
usage | object creation | mixin facility, provide a name space. |
super class | module | object |
consists of | methods, constants and variables | methods, constants and classes |
methods | class methods, instance methods | module methods, instance methods |
inheritance | inherits behaviour and can be base for inheritance | No inheritance |
inclusion | cannot be included | can be included in classes and modules by using the include command (includes all instance methods as instance methods in class/module) |
extension | cannot be extend with extends | module can extend instance by using extend command (extends given instance with singleton methods from module) |