Shouldn't there be a class to encapsulate what is returned by each array
entry in from
caller so that we don't have to take it apart with a regex?

For example caller could return an array of ProgramCounter objects where

ProgramCounter = Struct.new("ProgramCounter", :filename, :linenum,
:method_name)

that way the code below would be

def method_name
  caller((1)[0]).method_name
end

Steve Tuckner

> -----Original Message-----
> From: Klaus Fabritius [mailto:kfk / wasserhase.de]
> Sent: Wednesday, November 27, 2002 10:47 AM
> To: ruby-talk ML
> Subject: Re: The names of a method
>
>
> Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> > on 02/11/27, Klaus Fabritius <kfk / wasserhase.de> writes:
>
> >|Is there a thing like the_name_the_method_was_called_with?
> >
> > caller(0) may help.
>
> Thanks to you and Bill.
>
> I hoped that there is something like local_variables. Well, now it is
> the first method in my own utils-package:
>
> def method_name
>   /`(.+)'$/.match(caller(1)[0])[1]
> end
>
> Hm, it should be the last method in the file because it kills syntax
> highlighting ;-)
>
>
>   -kfk
>
> --
> UNIX has grown fat.
>
>          -Rob Pike, 1983