From: Austin Ziegler Date: 2002-11-27T09:55:05+09:00 Subject: Re: The names of a method This is a multipart message in MIME format --28847658-POCO-17223350 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable On Wed, 27 Nov 2002 08:54:07 +0900, Yukihiro Matsumoto wrote: > caller(0) may help. > > % ri caller [...] > Returns the current execution stack---an array containing= strings > in the form ``file:line'' or ``file:line: in `method'''. The > optional anInteger parameter determines the number of initial > stack entries to omit from the result. [...] > c(0) #=3D> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10"] > c(1) #=3D> ["prog:5:in `b'", "prog:8:in `c'", "prog:11"] > c(2) #=3D> ["prog:8:in `c'", "prog:12"] > c(3) #=3D> ["prog:13"] I use caller(0) in one of the functions that I've translated, and= I have to say that I really don't like it for a few reasons. I've= only just identified the core reason that I don't like it. It returns= an Array of Strings, which then have to be parsed in one of two optional forms. Shouldn't it return an Array of Calls, where a Call contains the same information as is in the string and, in fact, has a #to_s= that outputs in the same form as what we see above? Right now, I= can't interact with the results of Caller in an "intuitively" OO= fashion, like I can (just about) with everything else in Ruby. I just quickly created a simulation of it with the attached caller.rb file, but I think that this should probably be the way that Caller works. I'm sure there are other things that= could/should be added, but I shouldn't have to "parse" the string manually= every time I want to deal with caller. Most of the time, I just want= to know the name of the method that called the current method. Note that for the replacement to caller that I'm incrementing= the caller parameter by one; this is so that the fact that there's= one more level of indirection present is hidden. -austin -- Austin Ziegler, austin@halostatue.ca on 2002.11.26 at= 19.07.57 --28847658-POCO-17223350 Content-Type: application/octet-stream; name="caller.rb" Content-Transfer-Encoding: Base64 Content-Disposition: attachment; filename="caller.rb" Y2xhc3MgQ2FsbAogIGRlZiBpbml0aWFsaXplKGNhbGxzdHIpCiAgICBpZiBjYWxsc3RyID1+IC9e KFxTKyk6KFxkKyk6aW4gYChcUyspJyQvCiAgICAgIEBmaWxlID0gJDEKICAgICAgQGxpbmUgPSAk MgogICAgICBAbWV0aG9kID0gJDMKICAgIGVsc2lmIGNhbGxzdHIgPX4gL14oXFMrKTooXGQrKSQv CiAgICAgIEBmaWxlID0gJDEKICAgICAgQGxpbmUgPSAkMgogICAgICBAbWV0aG9kID0gbmlsCiAg ICBlbmQKICBlbmQKCiAgYXR0cl9yZWFkZXIgOmZpbGUsIDpsaW5lLCA6bWV0aG9kCgogIGRlZiBo YXNfbWV0aG9kPwogICAgIUBtZXRob2QubmlsPwogIGVuZAoKICBkZWYgdG9fcwogICAgaWYgaGFz X21ldGhvZD8KICAgICAgIiN7QGZpbGV9OiN7QGxpbmV9OmluIGAje0BtZXRob2R9JyIKICAgIGVs c2UKICAgICAgIiN7QGZpbGV9OiN7QGxpbmV9IgogICAgZW5kCiAgZW5kCmVuZAoKbW9kdWxlIEtl cm5lbAogIGFsaWFzX21ldGhvZCA6Y2FsbF9jYWxsZXIsIDpjYWxsZXIKCiAgZGVmIGNhbGxlcihs ZXZlbCA9IDApCiAgICBjYWxsX2NhbGxlcihsZXZlbCArIDEpLmNvbGxlY3QgeyB8eHwgQ2FsbC5u ZXcoeCkgfQogIGVuZAplbmQKCmlmIF9fRklMRV9fID09ICQwCiAgZGVmIGEoc2tpcCkKICAgIGNh bGxlcihza2lwKQogIGVuZAoKICBkZWYgYihza2lwKQogICAgYShza2lwKQogIGVuZAoKICBkZWYg Yyhza2lwKQogICAgYihza2lwKQogIGVuZAoKICBwIGMoMCkKICBwIGMoMSkKICBwIGMoMikKICBw IGMoMykKZW5kCg== --28847658-POCO-17223350--