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

E

Eric C.

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
 
K

Kirk Haines

Hi:

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

class MyClass

=A0def instance_method
=A0 =A0puts self.class.name =A0# =3D> "MyClass"
=A0end

=A0def self.class_method
=A0 =A0self.class.name # =3D> Undefined
=A0 =A0how can I get class.name here?
=A0end
end

class MyClass
def self.class_method
self.name
end
end
 

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

Forum statistics

Threads
473,979
Messages
2,570,185
Members
46,725
Latest member
LeonidaTul

Latest Threads

Top