Suppose every publication needs a publisher, but magazines also need an editor. Ruby lets Magazine inherit the shared behavior from Publication while defining its own. In `class Magazine < Publication`, `<` names Publication as Magazine’s superclass. A Magazine instance can call both the inherited `publisher` methods and its own `editor` methods. section 3.5
class Publication
attr_accessor :publisher
end
class Magazine < Publication
attr_accessor :editor
end
The two class definitions show the superclass relationship and the separate attributes contributed by each class. section 3.5
The chain can continue: `class Ezine < Magazine` gives Ezine instances methods from both Magazine and Publication, even if Ezine defines no new methods. More generally, an instance can use instance methods defined in its class or its ancestral classes. Ruby finds a matching method along a method-lookup path; that path can include modules as well as classes. section 3.5 section 4.2.1
Each Ruby class has only one superclass. That makes inheritance useful for sharing methods, but not a way to express every relationship with classes alone. Modules can supply shared behavior without occupying a class’s one superclass position. When choosing between them, consider whether you are modeling an entity that needs instances or a characteristic shared by several entities. section 3.5.1 section 4.4.1
Choosing a superclass or a mixin
A CargoHold can inherit stack operations from Stack, then define loading and unloading methods that use them. This works, but commits CargoHold’s sole superclass position to Stack. Mixing in a module containing the stack operations leaves that position available for another superclass. section 4.4.1
Inheritance can express an “is a” relationship: an Ezine is a Magazine, and `is_a?` can check whether an object belongs to a class in its ancestry. That family tree does not completely determine an object’s behavior. An individual object can gain a method, and adding an instance method to its class or an ancestor can change what it can do later. section 3.8


















