ruby picture

RCR 15: Replace 'caller' with 'call_stack'

Submitted by legacy (Mon Jul 30 20:07:14 UTC 2001)

Abstract

This is a legacy RCR from Ruby Garden, submitted by dave. Matz has declared these RCRs obsolete, and asked that their authors resubmit them in the new format.

Replace 'caller' with 'call_stack' returning an array of arrays each with the format:


    
      [object_called, method_called_id, args, file_with_call, line_for_call]

    

'call_stack' takes a level parameter (almost) in the same way as 'caller'. Example:


    
      def m(a,b)
        puts call_stack.inspect
      end
      def m2(a,b)
        m(a,b)
      end      m2(1,true)

    

would print


    
      [[main, :m, [1, true], "../call_stack/t2.rb", 5], [main, :m2, [1, true],
      "../call_stack/t2.rb", 8]]

    

It might also be useful to add any blocks associated with calls (I'm skeptical if this adds enough value for the added complexity).

Maybe there's a risk in including the args. I'm not sure... Probably there's a risk in any of this since Matz hasn't previously included it?

Problem

(RCR imported from old format)

Proposal

Analysis

(RCR imported from old format)

Implementation

(RCR imported from old format)
ruby picture
Comments Current voting

Don't replace, but add.. (Dave, 2001-07-30 19:46:16)

I've voting (mildly) for this one, but on condition we don't replace caller, but rather add a new method.--Dave

Here's a patch that does some of that... (WayneConrad, 2001-10-19 17:56:40)

See > for a patch that does some (but not all) of this request. I hadn't thought of providing the calling object (right now I provide the class), nor had I thought of the arguments. I'll take a look and see if those are reasonable/easy things to add to the patch.

Add bindings (, 2002-05-21 02:45:28)

I feel like it would be even more useful if there was a way of getting the bindings too, like in set_trace_proc().

Jean-Hugues

I'd rather do it this way: (matju, 2003-08-04 12:40:29)

RCR #29 : More Reflection :

(which is partially accepted, but i don't know what of it will go into ruby, and _when_)


Strongly opposed 0
Opposed 0
Neutral 0
In favor 0
Strongly advocate 0
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .