From: transfire@... Date: 2006-06-08T23:48:43+09:00 Subject: Re: Why the lack of mixing-in support for Class methods? ara.t.howard@noaa.gov wrote: > indeed. still - i see it being a bit anti POLS from someone's perspective, > that's all. Fair enough. No doubt it will come with it's own set of considerations with which we progammers will have to become familiar. > > 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 > I think one would need to set that up oneself using a class variable. Rather I would expext this it to behave like it does, just as with a class: class X def self.x @x end @x = 10 end class Z < X end X.x #=> 10 Z.x #=> 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' > You bring up your traits library all the time ;) Actually all-in-all I think it's pretty good. Unfortuately I have this one nagging problem with it. I think the term 'traits' is a terrible misnomer. That may seem silly but having done some study of prototype-base OOPS, especially Self, traits are just a totlatlly different concept to me. T.