# Help with call\_stack

**URL:** <https://www.ruby-forum.com/t/help-with-call-stack/92044>\
**Category:** Ruby\
**Created:** [April 15, 2007, 6:20am UTC](https://www.ruby-forum.com/t/help-with-call-stack/92044 "2007-04-15T06:20:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benjamin\_Paul\_Kay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3d9bf3/32.png) [@Benjamin\_Paul\_Kay](https://www.ruby-forum.com/u/Benjamin_Paul_Kay)\
**Post date:** [April 15, 2007, 6:20am UTC](https://www.ruby-forum.com/t/help-with-call-stack/92044/1 "2007-04-15T06:20:23Z")

</div>

Hi! I’m new to the mailing list, and I was hoping to get some help with  
call\_stack. I’m running Ruby 1.8.5, and I’ve installed the  
call\_stack-0.1.0.0 gem. Here’s a quick test file, test.rb:

### 

require ‘call\_stack’  
call\_stack\_on

class TestClass  
def a  
call\_stack(-1).each { |element| puts “class=#{element[0].to\_s},  
self=#{eval(‘self’,element[4])},  
self.class=#{eval(‘self’,element[4]).class}” }  
end  
def b  
puts “Method a is called from self=#{self},  
self.class=#{self.class}”  
a  
end  
end

test = TestClass.new  
puts “Method a is called from self=#{self}, self.class=#{self.class}”  
test.a  
test.b

### 

Running it produces the following output:  
$ ruby test.rb  
Method a is called from self=main, self.class=Object  
class=unknown, self=#TestClass:0x2b30b0177800, self.class=TestClass  
class=TestClass, self=Kernel, self.class=Module  
Method a is called from self=#TestClass:0x2b30b0177800,  
self.class=TestClass  
class=unknown, self=#TestClass:0x2b30b0177800, self.class=TestClass  
class=TestClass, self=Kernel, self.class=Module  
class=TestClass, self=Kernel, self.class=Module

Also tried adding “require ‘breakpoint185’” to the beginning of test.rb.  
That just made things worse:  
$ ruby test.rb  
Method a is called from self=main, self.class=Object  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=TestClass, self=Kernel, self.class=Module  
Method a is called from self=#TestClass:0x2abc3dc77f80,  
self.class=TestClass  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=unknown, self=#TestClass:0x2abc3dc77f80, self.class=TestClass  
class=TestClass, self=Kernel, self.class=Module  
class=TestClass, self=Kernel, self.class=Module

I’m a bit confused. In both cases I was expecting something more like:  
Method a is called from self=main, self.class=Object  
class=TestClass, self=#TestClass:0x2b30b0177800, self.class=TestClass  
class=Module, self=Kernel, self.class=Module  
Method a is called from self=#TestClass:0x2b30b0177800,  
self.class=TestClass  
class=TestClass, self=#TestClass:0x2b30b0177800, self.class=TestClass  
class=TestClass, self=#TestClass:0x2b30b0177800, self.class=TestClass  
class=Module, self=Kernel, self.class=Module

In particular, why is the the call\_trace(-1)[n][0] not the same as  
eval(‘self’,call\_trace(-1)[n][4]).class, and why does call\_trace(-1)[1]  
seem to point to the kernel when method a is called from inside method  
b?

Thanks for your patience and help,  
Benjamin Kay
