Unit 01 of 02
Classes and Modules
Instance variables living in the object and methods in the class, inheritance and reaching the superclass with super, sharing behavior without multiple inheritance through modules, public, protected and private methods, and how the ancestor chain is resolved.
Published Updated
Lessons
- 01 Class Definition and Instance Variables Classifying who wrote a method with four authors; instance variables living in the object and methods in the class; initialize being private; how a method written with attr_reader differs from one written with def. 15 min read
- 02 Inheritance and `super` An empty subclass taking a method from its superclass; the ancestor chain with superclass and ancestors; super in an overriding method; super inside initialize; the difference between bare super and super(...). 3 min read
- 03 Modules and Mixins How a module differs from a class; mixing a module into the ancestor chain with include; Comparable and <=>; order among two modules of the same name; extend on a single object. 15 min read
- 04 Visibility Public, protected and private methods; refusal of a call from outside, the difference between send and public_send, the self receiver, a protected method working on another object of the same class, and changing visibility in a subclass. 14 min read
- 05 The Method Lookup Chain How a method is searched in the ancestor chain when a message reaches the receiver; a prepended module, super_method, the end of the chain, the chain of class methods and a singleton method added to a single object. 14 min read