Multiple Inheritance, Ruby



Multiple inheritance is a feature of object-oriented computer programing
languages in which a class can inherit(Inheritance is a relation between two classes)
characteristics and features from more than one superclass.  It is distinct
to single inheritance, where a class may only inherit from one particular superclass.

Ruby doesn't support Multiple inheritance . Ruby has single inheritance(each class has one and only one parent class). Example: All cats are mammals, and all mammals are animals.The benefit of inheritance is that classes lower down the hierarchy get the features of those higher up, but can also add specific features of their own. If all mammals breathe, then all cats breathe. class ClassA puts :A end class ClassB puts :B end # will not work class Inheritor < ClassA, ClassB puts :A puts :B end # To make things work: module ModuleA puts :A end module ModuleB puts :B end # class Inheritor mixin ModuleA,ModuleB modules class Inheritor include ModuleA include ModuleB puts :I end I hope it give small clarification on ruby inheritance features.
Advertisements

2 thoughts on “Multiple Inheritance, Ruby

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s