# The name of an class?

**URL:** <https://rubytalk.org/t/the-name-of-an-class/12223>\
**Category:** ruby-talk\
**Created:** [20 June 2004 22:19 UTC](https://rubytalk.org/t/the-name-of-an-class/12223 "2004-06-20T22:19:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl-Heinz\_Wild](https://avatars.discourse-cdn.com/v4/letter/k/bc79bd/32.png) [@Karl-Heinz\_Wild](https://rubytalk.org/u/Karl-Heinz_Wild)\
**Post date:** [20 June 2004 22:19 UTC](https://rubytalk.org/t/the-name-of-an-class/12223/1 "2004-06-20T22:19:29Z")

</div>

maybe a dummy question. sorry.

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

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

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

thanks  
Karl-Heinz

---

<div class="post-metadata">

**Author:** ![Aredridel1](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Aredridel1](https://rubytalk.org/u/Aredridel1)\
**Post date:** [20 June 2004 22:31 UTC](https://rubytalk.org/t/the-name-of-an-class/12223/2 "2004-06-20T22:31:28Z")

</div>

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

class Base  
&nbsp;&nbsp;&nbsp;def theName  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.class.name  
&nbsp;&nbsp;&nbsp;end  
end

> **···**
>
> On Mon, 2004-06-21 at 07:19 +0900, Karl-Heinz Wild wrote:
> 
> > maybe a dummy question. sorry.
> > 
> > class Base  
> > &nbsp;&nbsp;def theName  
> > &nbsp;&nbsp;&nbsp;&nbsp;# the name i would like return should be "Question" mean the name of  
> > the class  
> > &nbsp;&nbsp;&nbsp;&nbsp;# calling this function  
> > &nbsp;&nbsp;end  
> > end
> > 
> > class Question \< Base  
> > &nbsp;&nbsp;def get( name )  
> > &nbsp;&nbsp;&nbsp;&nbsp;File.open( theName, 'r' ).each { | line |  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts line  
> > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > &nbsp;&nbsp;end  
> > end
> > 
> > how can i get the name "Question" in a String. I need this as an  
> > identifier.
