Inheritance in Ruby
So far, we’ve looked at a few features that come with Ruby’s implementation of the OOP paradigm, but we have neglected to look at one of the core features that help us recycle code. Inheritance can be simplified as the practice of passing the features of a class to create a brand-new child class. With this new class, we can use any of the features from the parent class, create new features, or customize the features that come from the parent class. The syntax for inheritance can be quite different than in PHP, but the behavior is quite similar. With that in mind, let’s take a look at a few use cases and see it in action.
Let’s say we wanted a class that would let us connect to a database. Instead of having to write all the functionality to connect to a database, we could get an already created database class, create a new one that inherited all the database functionality, and then focus on creating just the features that we need. This...