On Thu, 5 May 2005, Carlos wrote: > [Ara.T.Howard / noaa.gov, 2005-05-04 20.44 CEST] >> hmm - seems like something like that could work alright... but this fails: > [...] >> it's not easy... > > If you don't need to distinguish between singleton classes for classes and > normal objects, what's the problem with > > def inside? > self.is_a?(Class) && > self.name.empty? > self.ancestors.first != self > end ha! first i noticed you made a typo (the first two lines are a no-op without another '&&') - and then i ran it anyhow. funny thing is it seems the last line is all that's needed (if defined in Class)! jib:~/eg/ruby > cat a.rb class Class def inside_metaclass? self.ancestors.first != self end end class << self p inside_metaclass? # true end class C p inside_metaclass? # false class << self p inside_metaclass? # true class << self p inside_metaclass? # true end end end p Class::new.inside_metaclass? # false class << Class::new p inside_metaclass? # true end p self.class.inside_metaclass? # false class << self p inside_metaclass? # true end jib:~/eg/ruby > ruby a.rb true false true true false true false true not bad! why do you suppose metaclasses don't have themselves as ancestors? or perhaps put a better way - why DO normal classes? this is great! (please - somebody show me that it's wrong before i run wild with it ;-) ) kind regards. -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 ===============================================================================