# Coerce via aliased methods

**URL:** <https://www.ruby-forum.com/t/coerce-via-aliased-methods/125988>\
**Category:** Development\
**Created:** [January 14, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/coerce-via-aliased-methods/125988 "2008-01-14T14:27:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yugui](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ac91a4/32.png) [@Yugui](https://www.ruby-forum.com/u/Yugui)\
**Post date:** [January 14, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/coerce-via-aliased-methods/125988/1 "2008-01-14T14:27:45Z")

</div>

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 method`plus’ 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

---

<div class="post-metadata">

**Author:** ![Yugui](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/ac91a4/32.png) [@Yugui](https://www.ruby-forum.com/u/Yugui)\
**Post date:** [January 29, 2008, 9:26am UTC](https://www.ruby-forum.com/t/coerce-via-aliased-methods/125988/2 "2008-01-29T09:26:21Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
