From: ara.t.howard@... Date: 2006-06-09T00:07:45+09:00 Subject: Re: Why the lack of mixing-in support for Class methods? On Thu, 8 Jun 2006 transfire@gmail.com wrote: > 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 right. it's just that 'inheritence' with object generally follows this pattern class B attr :b def initialize() @b = 'bar' end end class C < B end p C.new.b #=> 'bar' which is to say there are mechanisms, namely initialize and super, for propagating state. no such mechanisms exist for class based state. if one is proposing an 'inherit' method (which i think is a great idea) then i think it's important to also toss around ideas for things like Class.class_init and/or Module.module_init - eg hooks that are provided to accomplish this. my preferred approach now is this module M module ClassMethods attr 'a' attr 'b' end module InstanceMethods end def self.included other other.extend ClassMethods other.module_eval{ include InstaneMethods } init other end def self.init other other.a = 42 other.b = 'forty-two' end end if we don't also consider this then the situation you describe in Nitro, where there a muliple ways of implimenting class method mixins, will more or less remain if any of those methods require state - that is to say it'd be a shame to make every ruby developer roll his is own way of initializing the required state for the module methods he could mix into his classes so easily. > You bring up your traits library all the time ;) yeah, not on purpose though: it just fills a lot of meta-programming and class inheritence niches which seems to come up often on this list. > 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. well - you can use the 'has' interface class C has 'c' => 42 class_has 'b' end it's just an alias - but if you hate the name... cheers. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama