new singleton class relationship

A

Ara.T.Howard

am i the only one who finds this confusing?

harp:~/build/ruby > cat a.rb
class Class
def singleton_class; class << self; self; end; end
end
class Parent
end
class Child < Parent
end

puts "Child < Parent #=> #{ (Child < Parent).inspect }"
puts "Parent.ancestors #=> #{ Parent.ancestors.inspect }"
puts "Child.ancestors #=> #{ Child.ancestors.inspect }"
puts

puts "Child.singleton_class < Parent.singleton_class #=> #{ (Child.singleton_class < Parent.singleton_class).inspect }"
puts "Parent.singleton_class.ancestors #=> #{ Parent.singleton_class.ancestors.inspect }"
puts "Child.singleton_class.ancestors #=> #{ Child.singleton_class.ancestors.inspect }"
puts


harp:~/build/ruby > ruby --version
ruby 1.8.3 (2005-05-16) [i686-linux]


harp:~/build/ruby > ruby a.rb
Child < Parent #=> true
Parent.ancestors #=> [Parent, Object, Kernel]
Child.ancestors #=> [Child, Parent, Object, Kernel]

Child.singleton_class < Parent.singleton_class #=> nil
Parent.singleton_class.ancestors #=> [Class, Module, Object, Kernel]
Child.singleton_class.ancestors #=> [Class, Module, Object, Kernel]


harp:~/build/ruby > ./ruby --version
ruby 1.9.0 (2005-05-16) [i686-linux]


harp:~/build/ruby > ./ruby a.rb
Child < Parent #=> true
Parent.ancestors #=> [Parent, Object, Kernel]
Child.ancestors #=> [Child, Parent, Object, Kernel]

Child.singleton_class < Parent.singleton_class #=> true
Parent.singleton_class.ancestors #=> [Class, Module, Object, Kernel]
Child.singleton_class.ancestors #=> [Class, Module, Object, Kernel]

so - how can 'Child < Parent #=> true' when they have no ancestors in common?
note that i think it __should__ be true - but shouldn't there be at least one
common ancestor then? it seems like Parent's singleton class should show up
in Child.singleton_class.ancestors doesn't it?

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
===============================================================================
 
C

Christoph

Ara.T.Howard said:
so - how can 'Child < Parent #=> true' when they have no ancestors in
common?
note that i think it __should__ be true - but shouldn't there be at
least one
common ancestor then? it seems like Parent's singleton class should
show up
in Child.singleton_class.ancestors doesn't it?

Ancestors apparently ignores singleton ancestors -
so this seems kind of alright to me.

/Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top