- An
Objectis a set of instance variables and a pointer to a 'singleton class'. - Properties are looked up in the instance variables, methods are dispatched via the singleton class.
Moduleis a subtype ofObject. AModuleis a set of methods and an ordered list of zero-or-more 'parent' modules.- Module
Abecomes a parent of moduleBviaB.include(A). - Method lookup works by doing a depth-first right-to-left search of a module tree.
Classis a subtype ofModule. AClassis aModulethat can be instantiated.- A
Classhas only one 'superclass'. A class includes its superclass as its first parent module for the purposes of method dispatch. A class's singleton class includes the superclass's singleton class as its first parent. - The default superclass of all classes is
Object. Objectincludes theKernelmodule as a parent.
- Although
Classis a subtype ofModule, you cannot callB.include(A)ifAis aClass. - Singleton classes are not really classes. You cannot instantiate or inherit from them.
obj.extend(M)is sugar forobj.singleton_class.include(M).