0 votes
in Ruby by
Explain Ruby module.

1 Answer

0 votes
by

Ruby module is a collection of methods and constants. A module method may be instance method or module method. They are similar to classes as they hold a collection of methods, class definitions, constants and other modules. They are defined like classes. Objects or subclasses can not be created using modules. There is no module hierarchy of inheritance.

Modules basically serve two purposes:

They act as namespace. They prevent the name clashes.

They allow the mixin facility to share functionality between classes.

Syntax:

module ModuleName  

statement1  

statement2  

...........  

end  

Module name should start with a capital letter.

...