Tobias DiPasquale wrote:

> I am writing a logger class for RubiCTM, and I was just wondering if I
> would be able to get the caller of the method inside a method. For
> instance, should the "xyz" method call <<Logger>>.log, <<Logger>>.log
> will know that the method that it was called from "xyz" and append that
> to the log message. Logger will be a Singleton, if that matters. Is
> there a way to find the most immediate method that the method was called
> from (Kernel.caller doesn't seem to be what I am looking for, or maybe
> it is... I'm not sure)?

Absorb this:

    set_trace_func proc { |event, file, line, id, binding, classname|
        printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
    }

Now instead of printing the arguments (which tends to flood an output 
stream), I suspect you could parse out the function names, push them into 
your own stack variable, and pop them out as they return. Then, outside 
this proc, whenever you needed to see the current call stack it's in your 
stack variable.

(I also suspect if you are writing a library you'd also need to chain to 
any user-supplied trace_func, or something.)

-- 
  Phlip                          phlip_cpp / yahoo.com
          http://www.greencheese.org/ParodyMode
  --  Proud victim of the dreaded boomerang effect  --