Eric_C
(Eric C.)
1
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
···
--
Posted via http://www.ruby-forum.com/.
class MyClass
def self.class_method
self.name
end
end
···
On Mon, Nov 29, 2010 at 10:49 PM, Eric C. <beagle4321_2000@yahoo.com> wrote:
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
Eric_C
(Eric C.)
3
Thank You!! It works. Seems so simple now
···
--
Posted via http://www.ruby-forum.com/.
Robert_K1
(Robert K.)
4
Or even just
class MyClass
def self.class_method
name
end
end
Hereby I grant you the first official "useless self" award of Rubyland.
Cheers
robert
PS: More awards at Partmaps.org
···
On Tue, Nov 30, 2010 at 6:59 AM, Kirk Haines <wyhaines@gmail.com> wrote:
On Mon, Nov 29, 2010 at 10:49 PM, Eric C. <beagle4321_2000@yahoo.com> wrote:
I'm writing a class where I need to know the class's name inside a class
method:
class MyClass
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
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/