From: "David A. Black" Date: 2005-11-24T11:51:58+09:00 Subject: Re: A question about metaclass Hi -- On Thu, 24 Nov 2005, Daniel Sheppard wrote: >> My question is where the C.new method is. >> The class Class or C's singleton class? >> >> According to PickAxe2, it seems that C.new is in Class. >> However, according to Little Ruby book, it seems that C.new >> is in C's metaclass. > > class C > end > > C.new #executed new from Class > > class C > def new(arg) You're defining C#new (an instance method of C). Do you mean to define: def C.new(arg) ? > p "ARGGGHHH!! #{arg}" > super.new If you are defining C.new, then super will return an instance of C: class C def C.new super end end C.new # # If you call new on that object, you'll get an NoMethodError :-) > end > end See if this helps: class C end p C.new def C.new puts "Here" super end p C.new > C.new #executed new from C's metaclass/singleton class/eigenclass. (class << obj; self; end) is obj's singleton class. Sometimes the singleton class of a class object is also called a "metaclass" (though there's been debate as to whether a separate term is needed, and whether "metaclass" is the best separate term). "Eigenclass" is just one of maybe 25 words that have been suggested for a future "official" term, since Matz has said he's thinking about what the best term might be. David -- David A. Black dblack@wobblini.net