aliasとcaller


#1

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

e$B85%M%?$Oe(B
http://www.yohasebe.com/diary/diary_search.php?id=142
e$B$J$N$G$9$,!"$3$N%9%/%j%W%H$O!"<B$O8=:_$Ne(B1.8e$B:G?7$*$h$Se(B1.9e$B$G$Oe(B
e$BF0:n$7$^$;$s!#e(B

e$BOC$rC1=c2=$7$F!"e(B

def method
caller.first.sub!(/^.*in `(?:.+?#)?(.+)$/, \1)
end

def foo
p method
end

alias bar foo
alias baz foo

foo
bar
baz

e$B$H$$$&%9%/%j%W%He(Btest.rbe$B$,$"$C$?$H$-!"e(B

% ruby-1.6 -v test.rb
ruby 1.6.8 (2003-07-27) [i586-mswin32]
foo
foo
foo

% ruby-1.8.1 -v test.rb
ruby 1.8.1 (2003-12-25) [i386-mswin32]
foo
bar
baz

% ruby-1.8.4 -v test.rb
ruby 1.8.4 (2005-12-25) [i386-mswin32]
foo
bar
baz

% ruby-1.8 -v test.rb
ruby 1.8.4 (2006-03-23) [i386-mswin32]
foo
foo
foo

% ruby-1.9 -v test.rb
ruby 1.9.0 (2006-03-26) [i386-mswin32]
foo
foo
foo

e$B$H$$$&$h$&$K!"e(B1.8e$B7O$N%j%j!<%9HG$N$_7k2L$,0[$J$j$^$9!#e(B

e$B<j85$K$Oe(B1.8.0e$B$,$J$+$C$?$N$G;n$7$F$^$;$s$,!"e(B1.8.0e$B$bB>$N%j%je(B

e$B!<%9HG$HF1MM$N7k2L$K$J$j$^$9!#e(B

aliase$B;~$Ne(Bcallere$B$O$I$&$J$k$Y$-$+!"$H$$$&OC$r9M$(;O$a$k$H!"$$$me(B
e$B$$$mFq$7$$$N$G$9$,!e(B1.8e$B%j%j!<%97ONsFb$G$N8_49@-$r9M$($k$H!>/e(B
e$B$J$/$H$be(B1.8e$B7O$G$Oe(Baliase$B$5$l$?L>A0$,<h$l$k$Y$-$G$"$k$H;W$$$^$9!#e(B
e$B$^$?!"$I$C$A$,JXMx$+!"$H$$$&OC$K$J$l$P!"e(Baliase$B$5$l$?L>A0$,<h$le(B
e$B$?J}$,JXMx$J5$$b$7$^$9!#e(B

1.9e$B$G$b!2a5ne(B(2004e$BG/$H$+e(B)e$B$Oe(Baliase$B$5$l$?L>A0$,<h$l$F$$$?$N$G$9e(B
e$B$,!e(B1.8e$B$K$;$he(B1.9e$B$K$;$h!$J$<e(Baliase$B$5$l$?L>A0$,<h$l$k$h$&$K$J$Ce(B
e$B$?$N$+!$J$<:#$O<h$l$J$/$5$l$?$N$+!"$H$$$&0U?^$O$h$/$o$+$j$^e(B
e$B$;$s!#e(B
e$B$H$$$&$o$1$G!"$U$+!<$$M}M3$,$=$3$K$"$k$J$i$PD|$a$^$9$,!"FC$Ke(B
e$B$J$$$J$i$48!F$$r4j$$$^$9!#e(B

e$B$$^$1$H$7$F!"e(B1.8e$B$$h$Se(B1.9e$B$=$l$>$lMQ$N=$@5e(B(?)e$B%Q%C%A$r$D$1$H$-e(B
e$B$^$9!#e(B

Index: eval.c

RCS file: /home/cvs/ruby/eval.c,v
retrieving revision 1.616.2.166
diff -u -1 -p -r1.616.2.166 eval.c
eval.c 23 Mar 2006 01:52:02 -0000 1.616.2.166
+++ eval.c 27 Mar 2006 13:05:11 -0000
@@ -6191,3 +6191,3 @@ backtrace(lev)
ruby_sourcefile, ruby_sourceline,

  •        rb_id2name(frame->orig_func));
    
  •        rb_id2name(frame->last_func));
    
    }
    @@ -6216,3 +6216,3 @@ backtrace(lev)
    n->nd_file, nd_line(n),
  •        rb_id2name(frame->prev->orig_func));
    
  •        rb_id2name(frame->prev->last_func));
    
    }

Index: eval.c

RCS file: /home/cvs/ruby/eval.c,v
retrieving revision 1.890
diff -u -1 -p -r1.890 eval.c
eval.c 23 Feb 2006 04:24:39 -0000 1.890
+++ eval.c 27 Mar 2006 13:05:21 -0000
@@ -1110,3 +1110,3 @@ error_line(struct FRAME *frame, NODE *no
return rb_sprintf("%s:%d:in `%s", file, line,

  •   		  rb_id2name(frame->this_func));
    
  •   		  rb_id2name(frame->callee));
      }
    

@@ -1123,3 +1123,3 @@ error_line(struct FRAME *frame, NODE *no
rb_class2name(oklass),

  •   		  rb_id2name(frame->this_func));
    
  •   		  rb_id2name(frame->callee));
      }
    

e$B$=$l$G$O!#e(B


#2

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message Re: [ruby-dev:28471] aliase$B$He(Bcaller
on Mon, 27 Mar 2006 22:07:19 +0900, U.Nakamura
removed_email_address@domain.invalid writes:

|1.9e$B$G$b!2a5ne(B(2004e$BG/$H$+e(B)e$B$Oe(Baliase$B$5$l$?L>A0$,<h$l$F$$$?$N$G$9e(B
|e$B$,!e(B1.8e$B$K$;$he(B1.9e$B$K$;$h!$J$<e(Baliase$B$5$l$?L>A0$,<h$l$k$h$&$K$J$Ce(B
|e$B$?$N$+!$J$<:#$O<h$l$J$/$5$l$?$N$+!"$H$$$&0U?^$O$h$/$o$+$j$^e(B
|e$B$;$s!#e(B
|e$B$H$$$&$o$1$G!"$U$+!<$$M}M3$,$=$3$K$"$k$J$i$PD|$a$^$9$,!"FC$Ke(B
|e$B$J$$$J$i$48!F$$r4j$$$^$9!#e(B

e$B$J$s$+JQ99$7$?$3$H$O3P$($F$k$s$G$9$,!"$=$NM}M3$r;W$$=P$;$^$;e(B
e$B$s!#$J$s$@$C$?$C$1!#$3$C$A$K$7$?J}$,$&$l$7$$$3$H$,$"$C$?$+$ie(B
e$B$N$h$&$J5$$,$9$k$s$G$9$,!#e(B

1.8e$B$OLa$9$H$7$F!"e(B1.9e$B$O$b$&$A$g$C$HM}M3$r9M$($^$9!#$-$C$H;W$$e(B
e$B=P$;$J$$$s$@$m$&$J!#;d$N5-21NO$C$?$i!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

#3

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message [ruby-dev:28479] Re: aliase$B$He(Bcaller
on Mar.29,2006 06:48:09, removed_email_address@domain.invalid wrote:
| 1.8e$B$OLa$9$H$7$F!"e(B1.9e$B$O$b$&$A$g$C$HM}M3$r9M$($^$9!#$-$C$H;W$$e(B
| e$B=P$;$J$$$s$@$m$&$J!#;d$N5-21NO$C$?$i!#e(B

e$B$H$j$"$($:e(B1.8e$B$GD>$C$F$k;v$r3NG$7$^$7$?!#e(B

e$B$5$F!"$3$3$GDs0F$J$N$G$9$,!e(B[ruby-dev:28471]e$B$K=q$$$?$h$&$J!e(B
__method__e$B%a%=%C%Ie(B(e$BL>A0$OE,Ev$G$9$,e(B)e$B$rF3F~$9$k$H$$$&$N$O$I$&e(B
e$B$G$7$g$&$+e(B?
e$B@h$Ne(Bbacktrace(e$B$^$?$Oe(Berror_line)e$B$NJQ99$G$Oe(Bcallere$B$N$$J$i$:%P%Ce(B
e$B%/%H%l!<%9$K$b1F6A$,=P$F$7$^$&$o$1$G$9$,!"$3$l$H$OFHN)$7$F8=e(B
e$B:
<B9TCf$N%a%=%C%IL>$,<h$l$k%a%=%C%I$,$$l$P!$3$N$h$&$JG:$_e(B
e$B$bH/@8$7$J$$$N$G$O$J$$$+$H;W$$$^$9!#e(B

e$B$J$!e(B__method__e$B$H$$$&L>A0$Oe(BC99e$B$Ne(B__func__e$B$+$i$NO"A[$G$O$$j$^e(B
e$B$9$,!"%j%F%i%k$G$O$J$/%a%=%C%I$H$7$F<BAu$9$k;v$r4|BT$7$F$$$ke(B
e$B$N$G!"e(B__FILE__e$B$de(B__LINE__e$B$H0c$C$F>.J8;zL>$,$7$C$/$j$/$k$N$G$Oe(B
e$B$J$$$+$H6r9M$7$F$
$j$^$9!#e(B

e$B$=$l$G$O!#e(B


#4

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message [ruby-dev:28482] Re: method (was Re:
aliase$B$He(Bcaller)
on Mar.29,2006 14:23:57, removed_email_address@domain.invalid wrote:
| |e$B$5$F!"$3$3$GDs0F$J$N$G$9$,!"e(B[ruby-dev:28471]e$B$K=q$$$?$h$&$J!"e(B
| |__method__e$B%a%=%C%Ie(B(e$BL>A0$OE,Ev$G$9$,e(B)e$B$rF3F~$9$k$H$$$&$N$O$I$&e(B
| |e$B$G$7$g$&$+e(B?
|
| e$B$3$N>l9g!JV$9$N$O85$N%a%=%C%IL>$J$s$G$9$+$M!#$=$l$H$be(Bcallee
| e$B$J$s$G$9$+$M!#e(B__method__e$B$,$$k$J$ie(B__callee__e$B$bI,MW$J$N$+$J!#e(B

e$B%P%C%/%H%l!<%9$O5lMh$N!"85$N%a%=%C%IL>$,=P$F!"e(B__method__e$B$G$Oe(B
aliase$B$5$l$?L>A0$,=P$k;v$rA[Dj$7$F$^$7$?!#e(B
e$B$,!"e(B__callee__e$B$bF1;~$K:NMQ$7$FN>J}<h$l$kJ}$,9,$;$]$$$G$9$M!#e(B

| e$B$=$NJU$,$O$C$-$j$7$?$i!"e(B1.9e$B$K$J$iF3F~$7$F$b9=$$$^$;$s!#e(B

e$B$^$@?<$/9M;!$7$F$J$$$N$G$9$,!"e(BObjecte$B%/%i%9$N%a%=%C%I$G$$$$$se(B
e$B$G$9$+$M$(!#e(B

e$B$=$l$G$O!#e(B


#5

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message Re: [ruby-dev:28481] method (was Re:
aliase$B$He(Bcaller)
on Wed, 29 Mar 2006 10:46:10 +0900, U.Nakamura
removed_email_address@domain.invalid writes:

|In message [ruby-dev:28479] Re: aliase$B$He(Bcaller
| on Mar.29,2006 06:48:09, removed_email_address@domain.invalid wrote:
|| 1.8e$B$OLa$9$H$7$F!e(B1.9e$B$O$b$&$A$g$C$HM}M3$r9M$($^$9!#$-$C$H;W$$e(B
|| e$B=P$;$J$$$s$@$m$&$J!#;d$N5-21NO$C$?$i!#e(B
|
|e$B$H$j$$($:e(B1.8e$B$GD>$C$F$k;v$r3NG$7$^$7$?!#e(B

e$B$=$&$$$($P!"e(Bbacktracee$B$N>pJs$r8+$l$P9THV9f$,$o$+$k$N$G%%j%8e(B
e$B%J%k$N%a%=%C%IL>$O<+L@$@$m$&!"$J$i$Pe(Baliase$B$5$l$?e(B(e$BD>@\8F$S=P$5e(B
e$B$l$?e(B)e$B%a%=%C%IL>$,$o$+$C$?$[$&$,$h$$$@$m$&$H$$$&H=CG$@$C$?$he(B
e$B$&$J5$$,$7$F$-$^$7$?!#$D$$$G$Ke(B1.8e$B$G$b$=$&$7$A$c$C$?$N$O@
$$e(B
e$BM>$C$?46$8$G$9$,!#e(B

|e$B$5$F!"$3$3$GDs0F$J$N$G$9$,!"e(B[ruby-dev:28471]e$B$K=q$$$?$h$&$J!"e(B
|__method__e$B%a%=%C%Ie(B(e$BL>A0$OE,Ev$G$9$,e(B)e$B$rF3F~$9$k$H$$$&$N$O$I$&e(B
|e$B$G$7$g$&$+e(B?

e$B$3$N>l9g!JV$9$N$O85$N%a%=%C%IL>$J$s$G$9$+$M!#$=$l$H$be(Bcallee
e$B$J$s$G$9$+$M!#e(B__method__e$B$,$$k$J$ie(B__callee__e$B$bI,MW$J$N$+$J!#e(B

e$B$=$NJU$,$O$C$-$j$7$?$i!"e(B1.9e$B$K$J$iF3F~$7$F$b9=$$$^$;$s!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

#6

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message [ruby-dev:28483] Re: method (was Re:
aliase$B$He(Bcaller)
on Mar.29,2006 14:42:04, removed_email_address@domain.invalid wrote:
| e$B$^$@?<$/9M;!$7$F$J$$$N$G$9$,!"e(BObjecte$B%/%i%9$N%a%=%C%I$G$$$$$se(B
| e$B$G$9$+$M$(!#e(B

e$B%0%m!<%P%k4X?t$G$$$$5$$,$7$F$-$?$N$G;n$7$K:n$C$F$_$^$7$?!#e(B
e$B$3$l$G$$$$$N$+$J!#e(B

% ruby -e
p method, callee
def foo
p method, callee
end
alias bar foo
foo
bar

nil
nil
:foo
:foo
:foo
:bar

Index: eval.c

RCS file: /home/cvs/ruby/eval.c,v
retrieving revision 1.890
diff -u -1 -p -r1.890 eval.c
eval.c 23 Feb 2006 04:24:39 -0000 1.890
+++ eval.c 30 Mar 2006 05:32:02 -0000
@@ -7675,2 +7675,26 @@ rb_exec_end_proc(void)

+static
+rb_f_method_name(void)
+{

  • struct FRAME* prev = ruby_frame->prev;
  • if (prev && prev->this_func) {
  • return ID2SYM(prev->this_func);
  • }
  • else {
  • return Qnil;
  • }
    +}

+static
+rb_f_callee_name(void)
+{

  • struct FRAME* prev = ruby_frame->prev;
  • if (prev && prev->callee) {
  • return ID2SYM(prev->callee);
  • }
  • else {
  • return Qnil;
  • }
    +}

void
@@ -7729,2 +7753,5 @@ Init_eval(void)

  • rb_define_global_function(method, rb_f_method_name, 0);
  • rb_define_global_function(callee, rb_f_callee_name, 0);
  • rb_define_method(rb_mKernel, send, rb_f_send, -1);

e$B$=$l$G$O!#e(B


#7

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message [ruby-dev:28488] Re: method (was Re:
aliase$B$He(Bcaller)
on Mar.30,2006 14:34:48, removed_email_address@domain.invalid wrote:
| e$B%0%m!<%P%k4X?t$G$$$$5$$,$7$F$-$?$N$G;n$7$K:n$C$F$_$^$7$?!#e(B
| e$B$3$l$G$$$$$N$+$J!#e(B

e$B$3$l$G$h$1$l$P!e(BRDoce$B$r$D$1$FF~$l$^$9$1$I!$$$$$G$7$g$&$+e(B?

e$B$H!"K:$l$kA0$K3NGe(B

e$B$=$l$G$O!#e(B