From: Robert Klemme Date: 2006-04-21T18:33:17+09:00 Subject: Re: how to figure out what class a method is in for a *class method*? 2006/4/21, Philip Hallstrom : > Hi all - > > Given the following bit of code, I'd like it to spit out "Cat" followed by > "Dog", but what I get now is "Object" twice. > > --------------------------------------------------------------- > class Animal > def self.what_am_i > self.class > end > end > > class Cat < Animal > end > > class Dog < Animal > end > > puts Cat.what_am_i > puts Dog.what_am_i > --------------------------------------------------------------- > > The closest I can get is self.object_id which prints out different ID's, > but I'd really like the name if I can get it... Let me get this straight: you have a class object and you want a method that returns this class object? The code that does what you want is this: def self.what_am_i? self end But this seems a rather weird thing to do... Did you actually try this? puts Cat, Dog You can even use the name, but the output won't differ puts Cat.name, Dog.name If your problem is something else, please let us know. Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/