Coerce via aliased methods

Yuguie$B$G$9!#e(B

Fixnume$B$Ne(Bcoercee$B$9$k1i;;$O!"%(%$%j%"%97PM3$G;HMQ$9$k$HNce(B
e$B30$r@8$8$k$h$&$G$9!#e(B
e$B<!$N%3!<%I$Oe(B1.8e$B$G$Oe(B"successfully coerced"e$B$H=PNO$7e(B
e$B$^$9$,!"e(Btrunke$B$G$Oe(BNoMethodErrore$B$rEj$2$^$9!#e(B

class CoerceExample
def coerce(operand)
return self, operand
end
def +(rhs)
p ‘successfully coerced’
end
end

class Fixnum
alias plus +
end

1.plus CoerceExample.new
<<

ruby 1.9.0 (2008-01-14 revision 0) [i686-darwin9.1.0]
coerce-bin.rb:14:in plus': super: no superclass methodplus’ for
#CoerceExample:0x1a6454 (NoMethodError)
from coerce-bin.rb:14:in `’

rb_num_coerce_bine$B$N<BAu$K$*$$$F!“e(B
rb_frame_this_func()e$B$,%(%$%j%”%9$N$[$&$NL>A0e(B(e$B$3$N>le(B
e$B9g!"e(B:plus)e$B$rJV$9$?$a$N$h$&$G$9!#e(B

coercee$B$N0UL#$+$i8@$C$F8F$S=P$7;~$NL>A0$r;H$&$H$$$&$N$O$b$C$He(B
e$B$b$i$7$$5$$b$9$k0lJ}!"e(B
e$B!Ve(Baliase$B$9$k$H5sF0$,JQ$o$k%a%=%C%I!W$H$$$&$N$O$A$g$C$H0[e(B
e$BMM$G$9!#e(B

rb_frame_this_funce$B$rD>$9$Y$-$J$N$+!"e(Brb_num_coerce_bine$B$re(B
e$BD>$9$Y$-$J$N$+$o$+$j$^$;$s$,!"e(B
e$B$3$l$N$?$a$K8=:_e(B1.9e$B$G$Oe(B 1 ** Rational(1, 2) e$B$,F0e(B
e$B$-$^$;$s!#e(B

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

In message “Re: [ruby-dev:33095] Coerce via aliased methods”
on Mon, 14 Jan 2008 22:27:03 +0900, Yugui [email protected]
writes:

|Fixnume$B$Ne(Bcoercee$B$9$k1i;;$O!“%(%$%j%”%97PM3$G;HMQ$9$k$HNce(B
|e$B30$r@8$8$k$h$&$G$9!#e(B
|e$B<!$N%3!<%I$Oe(B1.8e$B$G$Oe(B"successfully coerced"e$B$H=PNO$7e(B
|e$B$^$9$,!"e(Btrunke$B$G$Oe(BNoMethodErrore$B$rEj$2$^$9!#e(B

|rb_num_coerce_bine$B$N<BAu$K$*$$$F!“e(B
|rb_frame_this_func()e$B$,%(%$%j%”%9$N$[$&$NL>A0e(B(e$B$3$N>le(B
|e$B9g!"e(B:plus)e$B$rJV$9$?$a$N$h$&$G$9!#e(B
|
|coercee$B$N0UL#$+$i8@$C$F8F$S=P$7;~$NL>A0$r;H$&$H$$$&$N$O$b$C$He(B
|e$B$b$i$7$$5$$b$9$k0lJ}!"e(B
|e$B!Ve(Baliase$B$9$k$H5sF0$,JQ$o$k%a%=%C%I!W$H$$$&$N$O$A$g$C$H0[e(B
|e$BMM$G$9!#e(B

e$B9M$($F$_$^$7$?$,!“85$NL>A0$r;H$&$Y$-$G$7$g$&$M!#$G!”$3$l$r$Ie(B
e$B$&D>$9$Y$-$+$G$9$,!#e(B

  • rb_frame_this_func()e$B$rD>$9e(B(e$B$N$OBgJQ$G$"$k$HA0$K$5$5$@$/e(B
    e$B$s$+$ie(B__caller__e$B$,$i$_$GJ9$$$?5$$,$9$ke(B)

  • rb_num_coerce_bin()e$B$rD>$9!#6qBNE*$K$OL@<(E*$K%a%=%C%IL>e(B
    e$B$r;XDj$9$k!#e(BAPIe$B$,JQ$o$k$,$I$&$;e(Brb_num_coerce_bin()e$B$O$[$He(B
    e$B$s$I$N?M$,;H$C$F$J$$$+$i!#e(B

e$B$I$C$A$G$9$+$M$(!#e(B