help with call_stack

B

Benjamin Paul Kay

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top