From: Ara.T.Howard@... Date: 2005-05-05T04:45:01+09:00 Subject: Re: [RCR] Object#inside_metaclass? On Thu, 5 May 2005, David A. Black wrote: >> There is a difference in meaning between the word singleton class and >> metaclass. The original poster was using the correct terminology and >> substituting the term "singleton class" would be incorrect. > > I disagree; I think Ara was using the term "metaclass" to mean "singleton > class". I'm taking my cue from his sample code: > > # (top level code) > > p inside_metaclass? # false > > class << self > p inside_metaclass? # true > end > > So his concept of "inside a metaclass" includes "inside a non-class object's > singleton class" (since top-level self is not a class). it does - but inadvertently. the only requirement i have is to determine 'inside_metaclass?' as in class C class << self p inside_metaclass? # true end end the singleton meaning accreted itself into my impl in a moment of stupidity ;-( > He then predicates that his code only works iff "all metaclasses descend > from the metaclass of Object", but if he's using "metaclass" to mean the > same thing he meant it to mean in "inside_metaclass?", then this means > singleton class (and the statement is false). you are right. i didn't mean it - honest! my need to is to have context sensitive class methods class C method # does something class << self method # does another thing end end and that's all. > (I'm working in the dark a little here as the examples all print 'false' for > me in 1.8.2 and slightly old 1.9. I guess Ara's using a recent 1.9 -- ?) hmm. here's mine: jib:~/eg/ruby > cat a.rb class Class def inside_metaclass? inspect =~ %r/^# ruby a.rb true false true true but this has been pointed out to break for anonymous classes. arggh. -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 ===============================================================================