A
Ara.T.Howard
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/^#<Class:/ ? true : false
end
end
class << self
p inside_metaclass?
end
class C
p inside_metaclass?
class << self
p inside_metaclass?
class << self
p inside_metaclass?
end
end
end
jib:~/eg/ruby > 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
===============================================================================