Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Object#caller and Exception#backtrace

Reply
Thread Tools

Object#caller and Exception#backtrace

 
 
Ben Giddings
Guest
Posts: n/a
 
      02-08-2005
Seeing the wonderfulness of the 'to_ruby' method I mentioned just
recently got me thinking about Object#caller and Exception#backtrace again.

I don't know about anybody else, but it seems strange to me that these
potentially really useful methods return an array of fixed strings. I'm
also puzzled by what information it is they return, and what they don't:

["exception.rb:84:in `start_juggernaut'",
"exception.rb:77:in `initialize'",
"exception.rb:108:in `new'",
"exception.rb:108"]

They return the filename and a line number, which is great. A method,
which is useful... but no class / module or other form of nesting? Does
anybody understand why that is? Is there any desire to fix it? I think
having the class/module, at least, would be hella-useful.

For my own sake, I've created a little bit of ruby code that defines a
couple of methods for Object (caller_as_arrays and caller_as_objects)
and for Exception (backtrace_as_arrays and backtrace_as_objects).

caller_as_arrays and backtrace_as_arrays return something like:

[["caller.rb", 84, "start_juggernaut"],
["caller.rb", 77, "initialize"],
["caller.rb", 106, "new"],
["caller.rb", 106]]

caller_as_objects and backtrace_as_objects return something like:

[#<Caller:0x402e6ccc
@filename="caller.rb",
@line_no=101,
@method_name="feets_dont_fail_me_now">,
#<Caller:0x402e6cb8
@filename="caller.rb",
@line_no=84,
@method_name="start_juggernaut">,
#<Caller:0x402e6ca4
@filename="caller.rb",
@line_no=77,
@method_name="initialize">,
#<Caller:0x402e6c90 @filename="caller.rb", @line_no=106,
@method_name="new">,
#<Caller:0x402e69d4 @filename="caller.rb", @line_no=106,
@method_name=nil>]

Would anybody find this useful? Any comments on the names of the
methods or objects? Shall I upload to rubyforge and figure out how to
gemificate?

Ben


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57