A module is a named bag of methods and constants. Mix it into a class and every instance gains those methods — no family tree required.
1 Modules Hold Code
module Name ... end groups methods and constants under one name.
2 include Mixes In
include Greetable inside a class makes every instance method of the module available.
3 Many Modules, One Class
A class can include several modules — behavior composes like building blocks.
4 Famous Mixins
Comparable and Enumerable power <, ==, map and select across all of Ruby.
Bundles of behavior
Modules Hold Code1module Name ... end groups methods and constants under one name. include Mixes In2include Greetable inside a class makes every instance method of the module available. Many Modules, One Class3A class can include several modules — behavior composes like building blocks. Famous Mixins4Comparable and Enumerable power <, ==, map and select across all of Ruby. 4 building blocks make up Bundles of behavior
Press Run to follow one method call up the ancestor chain.
Greetable has no objects of its own — but every Robot gains greet the moment the module is included.
mainmodule Greetable opens a bundle of reusable methods — no objects can be made from it.
Memory
no variables yet — press play
Console
output appears as the program runs…
A mixin method pushes its frame like any other — it just lives in a module. Play the script, then drag to orbit.
Drag to orbit the scene. Press Play to watch memory in action.
Click a term, then click its description to lock the pair.
5 conceptsTap a card to expand ?moduledrops into place
?includedrops into place
?ancestorsdrops into place
?Comparabledrops into place
?Enumerabledrops into place
01A module bundles methods and constants; it cannot be instantiated.
02include splices the module into the ancestor chain of the class.
03Method lookup order: the class first, then its modules, then superclasses.
04Mixins share behavior across unrelated classes — no deep hierarchy needed.
05Comparable and Enumerable are stdlib mixins worth studying.