Revisions
-
jcoglan created this gist
Feb 18, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ ### Core ideas * An `Object` is 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. * `Module` is a subtype of `Object`. A `Module` is a set of methods and an ordered list of zero-or-more 'parent' modules. * Module `A` becomes a parent of module `B` via `B.include(A)`. * Method lookup works by doing a depth-first right-to-left search of a module tree. * `Class` is a subtype of `Module`. A `Class` is a `Module` that can be instantiated. * A `Class` has 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`. * `Object` includes the `Kernel` module as a parent. ### Warts * Although `Class` is a subtype of `Module`, you cannot call `B.include(A)` if `A` is a `Class`. * Singleton classes are not really classes. You cannot instantiate or inherit from them. ### Sugar * `obj.extend(M)` is sugar for `obj.singleton_class.include(M)`.