the name of an class?

K

Karl-Heinz Wild

maybe a dummy question. sorry.

class Base
def theName
# the name i would like return should be "Question" mean the name of
the class
# calling this function
end
end

class Question < Base
def get( name )
File.open( theName, 'r' ).each { | line |
puts line
}
end
end

how can i get the name "Question" in a String. I need this as an
identifier.

thanks
Karl-Heinz
 
A

Aredridel

maybe a dummy question. sorry.

class Base
def theName
# the name i would like return should be "Question" mean the name of
the class
# calling this function
end
end

class Question < Base
def get( name )
File.open( theName, 'r' ).each { | line |
puts line
}
end
end

how can i get the name "Question" in a String. I need this as an
identifier.

I think that what you want is self.class.name --

class Base
def theName
self.class.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

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top