Ruby

36
1361 reads

February 28, 2013

Simple Module


A simple Module Example

37
1385 reads

February 28, 2013

Scope Resolution Operator


As with classes, you may use the double-colon scope resolution operator to access constants (including classes and other modules) declared inside modules.

27
1342 reads

February 28, 2013

Mix-In With Care


While each class can only descend from one superclass, it can mix in numerous modules.

31
1284 reads

February 28, 2013

Modules4


Modules can be thought of as discrete code units which can simplify the creation of reusable code libraries.

40
1331 reads

February 28, 2013

Modules3


The process of including a module is also called ‘mixing in’ – which explains why included modules are often called ‘mixins’.

27
1335 reads

February 28, 2013

INCLUDED MODULES OR ‘MIXINS’


An object can access the instance methods of a module by including that module using the include method.

26
1429 reads

February 28, 2013

Modules as Namespaces


You can think of a module as a sort of named ‘wrapper’ around a set of methods, constants and classes.

21
1305 reads

February 28, 2013

Modules_classes


the Class class is itself a descendent of the Module class. It inherits the behaviour of Module and adds on some important new behaviour – notably the ability to create objects.

37
1352 reads

February 28, 2013

Module Instance


Find out what a module really is. It turns out that, as with most other things in Ruby, a module is an object. Each named module is, in fact, an instance of the Module class

38
1338 reads

February 28, 2013

Module Function


If you want a function to be available both as an instance and a module method, you can use the module_function method with a symbol matching the name of an instance method