Rails supports single object inheritance. This means a class can have one parent class and will inherit all the methods and attributes belonging to that class. We define inheritance relationships using the < operator.
For example, let's say we'd like to define a particular type of pet, say a small and fluffy kitten. Let's create a kitten class that can inherit from our Pet class:
class Kitten < Petdef play_tennisputs "I am now playing tennis"endend
Our kitten now has all the attributes of a pet. It can shoot fire from it's eyes, and play some good chess, but in addition it can also play tennis:
tiger = Kitten.newtiger.play_tennis=> I am now playing tennistiger.shoot_fire=> now shooting fire
Exercise - Subclasses
Extend your Fluffster / Warship exercise from before. Create a subclass of warship, perhaps a frigate, that has different abilities.