From: m4dc4p Date: 2005-10-08T06:16:50+09:00 Subject: Re: newb: Class Method determining it's actual class? It's like lighting a cigarette while waiting for the bus. Nothing guarantees faster arrival, haha! Art Gillespie wrote: > Hi again, > > There must be some law somewhere says that the chances of finding the > answer yourself goes up exponentially in the moments after posting to > a mailing list. > > I hadn't even thought to try 'self' in a class method. Much to learn. > > Thanks again, > > Art > > On 10/7/05, Art Gillespie wrote: > > Hi, > > > > New to Ruby and to the list. I've looked through pickaxe and through > > the ruby source code and haven't figured this one out. > > > > With the built-in File class, if I derive from it and call a class > > method (e.g., open) what I get back is an instance of my derived > > class: > > > > class IFFFile < File > > end > > > > f = IFFFile.open("media.iff", "r") > > > > f.class => "IFFFile" > > > > How does one do this with their own class methods? > > > > class A > > def A.open > > #how do we know here if the message recipient is a subclass of A? > > #i.e., can't we generalize it so that it is, in effect, class.new? > > A.new > > end > > end > > > > Many thanks for any pointers to what I'm missing. > > > > Art > > > >