title: Ruby: Is it possible to determine the class that my Ruby method is executing in without hardcoding the classname?
body: <p>I am a Nuby to Ruby. I am looking for a way to get the containing Class object of the method of the current line of execution. Is this possible without hardcoding the classname? </p>
  
  <pre><code># hardcoded example
  class A
    def to_s
      "I am a " + A.to_s   # Class "A" is hardcoded here. Is there another way to reference the class A?
    end
  end
  </code></pre>
  
  <p>I thought that maybe <code>self.class</code> would work, but it didn't give me what I was looking for when the class is subclassed.</p>
  
  <pre><code># Following Outputs=&gt; I am a Camel I am a Camel I am a Camel
  # but I want       =&gt; I am a Camel I am a Mammal I am a Animal
  
  class Animal
    def to_s
      "I am a " + self.class.to_s
    end
  end
  
  class Mammal &lt; Animal
    def to_s
      "I am a " + self.class.to_s + " " + super
    end
  end
  
  class Camel &lt; Mammal
    def to_s
      "I am a " + self.class.to_s + " " + super
    end
  end
  
  puts Camel.new()
  </code></pre>
  
  <p>So, is there a keyword, method or something that allows accessing the containing class?</p>