From: Ryan Davis Date: 2002-09-20T18:35:36+09:00 Subject: RFC: Need a better caller(n) - real reflection for call stack wanted RubyInline has the following extension to Object: def caller_method_name() /\`([^\']+)\'/.match(caller(2).first)[1] end Is there a better way???? caller(n) returns a string, and I have to parse it for the method name. This is scary at best. I'd much rather have something that gave me either the method instance itself, or some instance representation of the call stack. Something like: class CallStack def line ... end # returns the line of the calling method at this level (ATL) def method ... end # returns the calling method ATL def class ... end # returns the class for the calling method ATL def to_s ... end # equivalent output to the regular caller(n) method def up ... end # returns a CallStack instance for one level up, or nil def down ... end # returns a CallStack instance for one level down, or nil end and a method, callstack() that returns the current instance of CallStack. Or something like that. it would change my above method to: def caller_method_name() callstack.up.up.method.name end Which reads MUCH better, and you can manipulate a lot more with this type of expression. I suppose up and down should also take int args like caller. Now I'm tempted to go implement this... :) Just not sure how my ruby-fu in the internals are.