July 2011
Intermediate to advanced
400 pages
8h 46m
English
Although each class can descend from only one superclass, it can mix in numerous modules. In fact, it is perfectly permissible to mix one lot of modules into another lot of modules, then mix those other modules into classes, then place those classes into yet more modules, and so on.
The following is an example of some code that subclasses some classes, mixes in some modules, and even subclasses classes from within mixed-in modules. I’ve deliberately simplified the following code to help you see what is happening. For the full horror of a working example, see the sample program, multimods.rb, which is supplied in the code archive for this chapter:
multimods.rb
# This is an example of how NOT to use modules! module MagicThing # module ...
Read now
Unlock full access