From: Joel VanderWerf Date: 2005-07-29T02:04:30+09:00 Subject: Re: What's so special about operators, built-in classes and modules? Jim Weirich wrote: > I found this particular entry to be less helpful than other resources. > The problem is rarely which method to call (which actually is not a > diamond inheritance problem ... it can arise whenever two base classes > share a method with a common name). The big problem with diamond > inheritance is the question of instance data ... do you have one or two > copies? > > (and given the way Ruby handles instance variables, I find it hard to > imagine the answer to this question would ever be two). Dim memory... wasn't there a proposal to have per-module (or class) instance variables, so that different parts of the inheritance chain don't step on each other? Wouldn't this introduce the diamond problem? Take a case like this: module Counts def inc @count ||= 0 @count += 1 end def cur @count end end module CountsDucks include Counts def saw_a_duck inc end def duck_count cur end end module CountsChickens include Counts def saw_a_chicken inc end def chicken_count cur end end class C include CountsDucks include CountsChickens end c = C.new c.saw_a_duck c.saw_a_duck c.saw_a_chicken p c.duck_count p c.chicken_count Now, the output is 3 3 But using per-module instance variables, you would want this to be 2 1 This seems like a case where you would want there to be two copies of the (ivars defined by the) Counts module.