| Start |
|---|
| Subclasses Inheritance allows classes to define specific behaviour based on an existing class. In this example:
|
| Multiple Inheritance Multiple inheritance is a feature that allows one class to inherit from multiple classes(i.e., more than one parent). Ruby does not support multiple inheritance. It only supports single-inheritance (i.e. class can have only one parent), but you can use composition to build more complex classes using Modules (opens new window). |
| What is inherited? Methods are inherited Class methods are inherited Constants are inherited But beware, they can be overridden: Instance variables are inherited: Beware, if you override the methods that initialize instance variables without calling Class instance variables are not inherited: Class variables aren't really inherited They are shared between the base class and all subclasses as 1 variable: So continuing from above: |
| Mixins Mixins (opens new window) are a beautiful way to achieve something similar to multiple inheritance. It allows us to inherit or rather include methods defined in a module into a class. These methods can be included as either instance or class methods. The below example depicts this design. |
| Refactoring existing classes to use Inheritance Let's say we have two classes, The We have created a new class, Syntax
|
Read Article
https://develop.horje.com/learn/1434/reference