Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

LESSON: ruby-object-inheritance



By the end of this, developers should be able to:

  • Diagram the Ruby method lookup chain
  • Write a class which inherits from another class.


Inheritance: They way objects inherit methods and properties from their parent classes.

Superclass: Classes themselves can inherit from other classes, and these parents classes of classes are called superclasses.

Method Lookup Chain: When a method is called on an object, it will look within it's own instance for methods with that name, and if not found, will go to the parent class and try to find the method, and if not found, go to that class' parent and try to find the method etc until either the method is found, and then run, or it is not found, returning nil / undefined .

Overriding: When a class inherits from a superclass and the superclass has a method that is also named in the child class, the child class is the method that gets called on objects, ie it overrides access to the superclass method and uses it's own method of the same name instead.