Any way to know a Class's name in class method?

Hi:

I’m writing a class where I need to know the class’s name inside a class
method:

class MyClass

def instance_method
puts self.class.name # => “MyClass”
end

def self.class_method
self.class.name # => Undefined
how can I get class.name here?
end

end

Thanks,
Eric

On Mon, Nov 29, 2010 at 10:49 PM, Eric C. [email protected]
wrote:

def self.class_method
self.class.name # => Undefined
how can I get class.name here?
end
end

class MyClass
def self.class_method
self.name
end
end

Thank You!! It works. Seems so simple now :slight_smile:

On Tue, Nov 30, 2010 at 6:59 AM, Kirk H. [email protected] wrote:

On Mon, Nov 29, 2010 at 10:49 PM, Eric C. [email protected] wrote:

I’m writing a class where I need to know the class’s name inside a class
method:

class MyClass

end
Or even just

class MyClass
def self.class_method
name
end
end

Hereby I grant you the first official “useless self” award of Rubyland.
:wink:

Cheers

robert

PS: More awards at Partmaps.org