From: ara.t.howard@... Date: 2006-06-08T22:26:55+09:00 Subject: Re: Why the lack of mixing-in support for Class methods? On Thu, 8 Jun 2006 transfire@gmail.com wrote: > Sigh. We've been through this Ara. It's a silly example --don't use those > methods if you don;t want to override them --and what if you do? indeed. still - i see it being a bit anti POLS from someone's perspective, that's all. > Nonethesless, I agree with Matz. I think a simple alternative call is > the prefect compromising solution. Perhaps: > > class C > inherit M > end i have my own impl ;-) > Also, This post is kind of timely, I'be been preparing a post with example's > from Nitro on the extensive need of this behavior --you should see the many > "hacks" being used to accomplish this there --I think at least three > different techinqes are being used throughout dozens of components. the one issue i see is with stateful methods - we don't currently have 'inheritable state'. eg module M class << self attr 'foo' end @foo = 42 end class A inherit M end class B < A end p M.foo #=> 42 p A.foo #=> nil p B.foo #=> nil A.foo = 'forty-two' p M.foo #=> 42 p A.foo #=> 'forty-two' p B.foo #=> nil traits addresses this. eg this works require 'traits' class M class_trait 'foo' => 42 end class A < M end class B < A end p M.foo #=> 42 p A.foo #=> 42 p B.foo #=> 42 A.foo = 'forty-two' p M.foo #=> 42 p A.foo #=> 'forty-two' p B.foo #=> 'forty-two' not a deal breaker - but i've found in that in many designs relying on class inheritence it's precisely this kind of information sharing one is trying to acheive via inheritence or mixing in class methods. just food for thought. if we start mixing in class methods then the strange behaviour of ruby's 'class variables' and 'class instance variables' will become a popular topic on this list. cheers. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama