Inheritance and Class Design

Lesson 15 of 20

Extend a class with class Dog < Animal, override its methods, and let super borrow the parent version exactly when you need it.

The big picture

Children learn from parents

A subclass starts with everything its parent has, then adds or overrides — and super is the trapdoor back up to the parent version.

< Inherits

class Dog < Animal gives Dog every method and behavior Animal defines.

Override by Redefining

Defining speak in Dog replaces Animals speak — the most specific version wins.

super Reaches Up

Inside an override, super calls the same method one level up with the same receiver.

is_a? Sees the Family

A Dog is_a? Animal — inheritance models genuine "is a" relationships.