# Which Class called my Class?

**URL:** <https://www.ruby-forum.com/t/which-class-called-my-class/148876>\
**Category:** Ruby\
**Created:** [September 17, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/which-class-called-my-class/148876 "2008-09-17T22:39:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zbrod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/278dde/32.png) [@zbrod](https://www.ruby-forum.com/u/zbrod)\
**Post date:** [September 17, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/which-class-called-my-class/148876/1 "2008-09-17T22:39:02Z")

</div>

I have a script that queries servers in our environment to assist with  
patch-levels etc… I am having an issue and need to backtrace which  
class called my class.

What I currently have  
print “\nCollectData Failed 2: in needDate != yes & package == none  
#{hostName}\n”

What I would like to have  
print “\nCollectData Failed 2: in needDate != yes & package == none  
#{hostName}, called from #{callingClass}\n”

collectdata.rb:class CollectData  
collectdata.rb: print “\nCollectData  
Failed 1: in package != none and needDate == no #{hostName}\n”  
collectdata.rb: print “\nCollectData  
Failed 2: in needDate != yes & package == none #{hostName}\n”  
collectdata.rb: print “\nCollectData  
Failed 3: in needDate == yes #{hostName}\n”  
collectdata.rb: print “\nCollectData  
Failed: #{hostName}\n”  
rpmlist.rb: rpmInfo =  
CollectData.new(hostName)  
rpmmysql.rb: rpmInfo2 =  
CollectData.new(hostName,package.signature)

This message is private and confidential. If you have received it in  
error, please notify the sender and remove it from your system.

---

<div class="post-metadata">

**Author:** ![zbrod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/278dde/32.png) [@zbrod](https://www.ruby-forum.com/u/zbrod)\
**Post date:** [September 17, 2008, 11:08pm UTC](https://www.ruby-forum.com/t/which-class-called-my-class/148876/2 "2008-09-17T23:08:10Z")

</div>

Zach B. wrote:

> I have a script that queries servers in our environment to assist with  
> patch-levels etc… I am having an issue and need to backtrace which  
> class called my class.
> 
> What I currently have  
> print “\nCollectData Failed 2: in needDate != yes & package == none  
> #{hostName}\n”
> 
> What I would like to have  
> print “\nCollectData Failed 2: in needDate != yes & package == none  
> #{hostName}, called from #{callingClass}\n”

If I understand correctly what you want, try using the command +caller+  
to get what you want. It returns an array with current stack trace.

TPR.
