From: Wilson Bilkovich Date: 2007-01-12T14:07:27+09:00 Subject: Re: inheritance concept in ruby On 1/11/07, Helder Ribeiro wrote: > > Wilson Bilkovich wrote: > > On 1/9/07, Kumar Tnj wrote: > > > Hi, > > > > > > Is ruby supports multiple inheritence. > > > I am the beginner of ruby. > > > simple code for ruby multiple inheritence. > > > > > > > To expand on what hemant said.. try running this code. > > > > class Useless > > def six > > 6 > > end > > end > > > > module AlsoUseless > > def seven > > 7 > > end > > end > > > > class Thing < Useless > > include AlsoUseless > > def five > > 5 > > end > > end > > > > thing = Thing.new > > puts thing.five > > puts thing.six > > puts thing.seven > > puts Thing.ancestors.inspect # Useless and AlsoUseless are shown. > > I'm also new to Ruby and I've never used anything with multiple > inheritance. This code is enlightening but I can't see how this is > different from multiple inheritance in practice except that AlsoUseless > is not a class and you don't use the '<' sign with it. > > In which cases do the two scenarious (M.I. and mixins) cause different > behaviors? Is it only related to member visibility? If yes, how > exactly? > Multiple Inheritance can be extremely complex, as Gregory Brown has pointed out. One complication is that you now have to have rules to 'break ties' when you write: def hello super end What if each of the parent classes has their own implementation of 'hello'. Which one is invoked? Mix-ins simplify this greatly, because there is still only one unambiguous superclass. If you have used Java, they are like having Interfaces containing working code, as well as just a list of what should be implemented.