title: Ruby Inheritance Get Caller Class Name
body: <p>I'm so lost. I know how to use caller to get the caller method, but what do you use the get the caller class?</p>
  
  <p>For example:</p>
  
  <pre><code>class Testing
    def return_caller_class
      return caller_class
    end
  end
  
  class Parent
  
    attr_accessor :test_me
  
    def initialize      
      self.test_me =  Testing.new
    end
  
  end
  
  class Child &lt; Parent
  end
  
  class GrandChild &lt; Child
  end
  
  test_Parent = Parent.new
  test_Child = Child.new
  test_GrandChild = GrandChild.new
  
  puts test_Parent.test_me.return_caller_class     =&gt; Parent
  puts test_Child.test_me.return_caller_class      =&gt; Child
  puts test_GrandChild.test_me.return_caller_class =&gt; GrandChild
  </code></pre>
  
  <p>Thank you!!!</p>
  
  <p>Edit:</p>
  
  <p>I've tried to do the following</p>
  
  <pre><code>class Testing
    def return_caller_class
      return caller[0][/`.*'/][1..-2]
    end
  end
  </code></pre>
  
  <p>And the output is:</p>
  
  <pre><code>{"
  "=&gt;Parent}    
  {"
  "=&gt;Child}
  {"
  "=&gt;GrandChild}
  </code></pre>
  
  <p>To explain better about my question.</p>
  
  <p>I would the output to display this instead</p>
  
  <pre><code>Parent
  Child
  GrandChild
  </code></pre>