From: Ara.T.Howard@... Date: 2005-05-04T04:04:42+09:00 Subject: Re: un_metaclass On Tue, 3 May 2005, Robert Klemme wrote: > Ara.T.Howard wrote: >> thoughts on how to do this >> >> class C >> class << self >> p un_metaclass #=> C >> end >> end >> >> ?? > > I'd prefer to call it #instance 'cause that's what it is. :-) this __seems__ ok: jib:~/eg/ruby/traits/traits-0.0.0 > cat x.rb class Module def instance_class m = %r/^(?:#+)$/io.match inspect if m klass_name, brackets = m[1], m[2] n = brackets.size - 1 klass = const_get klass_name n.times{ klass = class << klass; self; end } klass else superclass end end end class C p instance_class class << self p instance_class class << self p instance_class class << self p instance_class end end end end class K < C p instance_class class << self p instance_class class << self p instance_class class << self p instance_class end end end end jib:~/eg/ruby/traits/traits-0.0.0 > ruby x.rb Object C # #> C K # #> i'm thinking 'instance_class' may be better... instance sounds like a singleton constructor or something... basically this is a cross between Module#nesting and Class#superclass : it yield the first class up the inheritence/singleton chain from the caller. thoughts? cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | renunciation is not getting rid of the things of this world, but accepting | that they pass away. --aitken roshi ===============================================================================