Refinement仕様

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

$BEZMKF|$N(BRefinement$B2q5D$G=P$?=IBj$K$D$$$F!#(B

$B0J2<$N;EMM8uJd$N$&$A$$$:$l$rA*$V$+$H$$$&OC$G$7$?!#(B

(a) re-open

$B0lEY(Busing$B$5$l$?%b%8%e!<%k(B($B$^$?$O%/%i%9(B)$B$r(Bre-open$B$7$?>l9g!"$=(B
$B$N%b%8%e!<%k(B/$B%/%i%9$NK\BN$G(Brefinement$B$,M-8z$+$I$&$+!#(B

(b) inheritance

using$B$5$l$?%b%8%e!<%k$r(Binclude$B$7$?%/%i%9(B($B$^$?$O%/%i%9(B)$B!"$*$h(B
$B$S(Busing$B$5$l$?%/%i%9$r7Q>5$7$?%/%i%9$NK\BN$G(Brefinement$B$,M-8z$+(B
$B$I$&$+!#(B

$B>e5-!"(B(a),(b)$B$H$b$KDj5A$N;zLL>e(Busing$B$,EP>l$7$J$$6ILL$G!"(B
refinement$B$,M-8z$+$I$&$+$H$$$&H=CG$K$J$j$^$9!#(Busing$B$,[email protected]<(E*(B
$B$KEP>l$7$J$$$N$K5sF0$,JQ2=$9$k$3$H$O:[email protected]$,$"$j$^(B
$B$9!#$^$?!"%b%8%e!<%k!&%/%i%9$NDj5A$,%m!<%I$5$l$k=g=x$K$h$C$F!"(B
$B5sF0$,JQ2=$7$F$7$F$7$^$&$3$H$G!“99$J$k:[email protected]$,$”$j$^$9!#(B

$B$5$i$KL$K8+$($kHO0O$K(Busing$B$,$J$$$3$H$G!":GE,2=$,Fq$7$$$H$$$&(B
$B$3$H$b$"$k$G$7$g$&!#(B

© module_eval

module_eval$B$r;H$C$?%H%j%C%/$O!">>ED$5$s$N(BRubyConf$BH/I=$G$b$"(B
$B$j!"$J$+$J$+6=L#?<$$%F%/%K%C%/$J$N$G$9$,!"$=$N0lJ}!“F1$8%3!<(B
$B%I$,(Brefinement$BM-8z$G8F$S=P$5$l$k$N$+3NDj$G$-$:!”:GE,2=$,Fq$7(B
$B$$>e$K!"%$%s%i%$%s%-%c%C%7%[email protected]$,0-$$$H$$$&LdBj$,$"$j$^$9!#(B

$B$A$J$$K8=>u$G$O(B(a),(b),©[email protected]$,!"(B©$B$K$D$$$F$O%$%s%i(B
$B%$%s%a%=%C%I%-%c%C%7%e$K4XO"$9$k?<9o$J%P%0$,$"$j!"(Br37616$B$G=$(B
[email protected]$,;n$
$i$l$?$,!"?<9o$JB.EYDc2<LdBj$K$h$j(Brevert$B$5$l$?!"$HG’(B
$B<1$7$F$$$^$9!#9g$C$F$k!)(B

$B$G!"=5Kv$D$i$D$i$H9M$($?$N$G$9$,!"(B

  • refinement$B$O%l%-%7%+%k$J$J$K$+$G$O$J$/!"%b%8%e!<%k!&%/%i(B
    $B%[email protected]$G$"$k(B

$B$H$$$&[email protected][email protected]$K$7$F!"(B(a),(b)$B$H$b$KM-8z$K$7$h$&$H;W$$$^$9!#(B
©$B$K$D$$$F$OG:[email protected]$N$G$9$,!"$+$J$j?<[email protected]$H;W$&$N$G!"(B

  • module_eval(&b)$B$N7A<0$O6X;_(B($BNc30(B)
  • $B$^$?$O(Brefinement$B>uBV$,0[$J$k>uBV$G$N%V%m%C%/$N<B9T$O6X;_(B

$B$N$$$:$l$+$G$O$I$&[email protected]$m$&$+$H;W$C$F$$$^$9!#A0<T$G$"$l$P>>ED%F(B
$B%/%K%C%/$,;H$($J$$$3$H$K$J$k$o$1$G!"8D?ME*$K$O8e<T$rK>$s$G$$(B
$B$^$9$,!“A0<T$G$b;EJ}$,$J$$$H;W$C$F$$$^$9!#>[email protected])Ls4KOB$N2DG=(B
[email protected]$O$”$k$N$G!#(B

$B;D$kLdBj$O(BTwitter$B$G!"[email protected]$5$s$,;XE&$7$?(Bprepend$B$H(Brefinement
$B$N4X78$G$9!#$D$^$j(B

class B
def foo
p :B
end
end

module A
refine B do
def foo
p [:refine, :A, :B]
end
end
end

module C
def foo
super
p :C
end
end

class B
prepend C
end

module D
using A
B.new.foo # => $B$J$K$,=PNO$5$l$k$+(B
end

$B$H$$$&LdBj$G$9!#A*Br;h$H$7$F$O(B

(1) refine$B$O(Bprepend$B$r4^$a$F$=$N%/%i%9$N%a%=%C%I$r>e=q$-$9$k(B
($B8=>u(B)$B!#$h$C$F=PNO$O(B[:refine, :A, :B]
(2) refine$B$O(Bprepend$B$G=$>~$5$l$kA0$N4pK%a%=%C%I$rCV$-49$($k!#(B

$B$N$$$:$l$+$G$9$,!";d$O$3$l$O(B(1)$B$,K>$^$7$$$H;W$$$^$9!#$D$^$j!"(B
$B%m!<%+%k$N;XDj$G$"$k(Brefinement$B$NJ}$,M%@[email protected]$H;W$&$+(B
$B$i$G$9!#[email protected]$7!"(B[ruby-dev:46477]$B$K$"$kC5:w<jK!$NDs0F$G$O!";d(B
$B$,M}2r$9$k8B$j$G$O<+F0E*$K(B(2)$B$N5sF0$K$J$k$N$G!"$=$NJU$O8!F$(B
$B$NM>CO$,$"$k$H;W$$$^$9!#(B

                            $B$^$D$b$H(B $B$f$-$R$m(B /:|)

(2012/11/12 18:32), Shugo M. wrote:

$B%V%m%C%/$r:n$C$?;~$H0[$J$k>uBV$H$$$&$3$H$G$O$J$/!"%V%m%C%/$r0lEY$G$b(B
$B<B9T$9$k$H$=$N;~$N(Brefinement$B$N>uBV$r3P$($F$*$$$F!"0c$&>uBV$G<B9T$7$?(B
$B;~$K%(%i!<$K$9$k$H$$$&M}2r$G9g$C$F$$$k$G$7$g$&$+(B?

$B%$%s%i%$%s%-%c%C%7%e$NLdBj$K$D$$$F$O!"[email protected]$5$s$N0F$G2r7h$5$l$=$&(B
$B$G$9$,!"$=$l$G$b!V(Brefinement$B>uBV$,0[$J$k>uBV$G$N%V%m%C%/$N<B9T$O6X;_!W(B
$B$7$?J}$,$h$$$H;W$o$l$^$9$+(B?
$B;EMME*$K$A$g$C$HHyL/$J5$$,$9$k$N$G$9$,!#(B

$B!!A4LLE*$K!$<BAu4^[email protected])8B$J$/$&$^$/$d$k(B
or
$B!!A4LLE*$K6X;_(B

$B$,$$$$$s$8$c$J$$$+$H;W$$$^$9!%(B

refinement $B$N>uBV$,0[$J$k>uBV!$$N%A%’%C%/$,$7$s$I$$5$$,$7$^$9!%(B

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B12$BF|(B 17:50 Yukihiro M. [email protected]:

module_eval$B$r;H$C$?%H%j%C%/$O!">>ED$5$s$N(BRubyConf$BH/I=$G$b$"(B
$B$j!"$J$+$J$+6=L#?<$$%F%/%K%C%/$J$N$G$9$,!"$=$N0lJ}!“F1$8%3!<(B
$B%I$,(Brefinement$BM-8z$G8F$S=P$5$l$k$N$+3NDj$G$-$:!”:GE,2=$,Fq$7(B
$B$$>e$K!"%$%s%i%$%s%-%c%C%7%[email protected]$,0-$$$H$$$&LdBj$,$"$j$^$9!#(B

$B$A$J$$K8=>u$G$O(B(a),(b),©[email protected]$,!"(B©$B$K$D$$$F$O%$%s%i(B
$B%$%s%a%=%C%I%-%c%C%7%e$K4XO"$9$k?<9o$J%P%0$,$"$j!"(Br37616$B$G=$(B
[email protected]$,;n$
$i$l$?$,!"?<9o$JB.EYDc2<LdBj$K$h$j(Brevert$B$5$l$?!"$HG’(B
$B<1$7$F$$$^$9!#9g$C$F$k!)(B

$B$O$$!#(B

$B$G!"=5Kv$D$i$D$i$H9M$($?$N$G$9$,!"(B

  • refinement$B$O%l%-%7%+%k$J$J$K$+$G$O$J$/!"%b%8%e!<%k!&%/%i(B
    $B%[email protected]$G$"$k(B

$B$H$$$&[email protected][email protected]$K$7$F!"(B(a),(b)$B$H$b$KM-8z$K$7$h$&$H;W$$$^$9!#(B

$BN;2r$7$^$7$?!#(B

©$B$K$D$$$F$OG:[email protected]$N$G$9$,!"$+$J$j?<[email protected]$H;W$&$N$G!"(B

  • module_eval(&b)$B$N7A<0$O6X;_(B($BNc30(B)
  • $B$^$?$O(Brefinement$B>uBV$,0[$J$k>uBV$G$N%V%m%C%/$N<B9T$O6X;_(B

$B$N$$$:$l$+$G$O$I$&[email protected]$m$&$+$H;W$C$F$$$^$9!#A0<T$G$"$l$P>>ED%F(B
$B%/%K%C%/$,;H$($J$$$3$H$K$J$k$o$1$G!"8D?ME*$K$O8e<T$rK>$s$G$$(B
$B$^$9$,!“A0<T$G$b;EJ}$,$J$$$H;W$C$F$$$^$9!#>[email protected])Ls4KOB$N2DG=(B
[email protected]$O$”$k$N$G!#(B

$B!V(Brefinement$B>uBV$,0[$J$k>uBV$G$N%V%m%C%/$N<B9T$O6X;_!W$H$$$&$N$O!"(B
$B%V%m%C%/$r:n$C$?;~$H0[$J$k>uBV$H$$$&$3$H$G$O$J$/!"%V%m%C%/$r0lEY$G$b(B
$B<B9T$9$k$H$=$N;~$N(Brefinement$B$N>uBV$r3P$($F$*$$$F!"0c$&>uBV$G<B9T$7$?(B
$B;~$K%(%i!<$K$9$k$H$$$&M}2r$G9g$C$F$$$k$G$7$g$&$+(B?

$B%$%s%i%$%s%-%c%C%7%e$NLdBj$K$D$$$F$O!"[email protected]$5$s$N0F$G2r7h$5$l$=$&(B
$B$G$9$,!"$=$l$G$b!V(Brefinement$B>uBV$,0[$J$k>uBV$G$N%V%m%C%/$N<B9T$O6X;_!W(B
$B$7$?J}$,$h$$$H;W$o$l$^$9$+(B?
$B;EMME*$K$A$g$C$HHyL/$J5$$,$9$k$N$G$9$,!#(B

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

In message “Re: [ruby-dev:46496] Re: Refinement$B;EMM(B”
on Mon, 12 Nov 2012 18:32:40 +0900, Shugo M.
[email protected] writes:

|$B!V(Brefinement$B>uBV$,0[$J$k>uBV$G$N%V%m%C%/$N<B9T$O6X;_!W$H$$$&$N$O!"(B
|$B%V%m%C%/$r:n$C$?;~$H0[$J$k>uBV$H$$$&$3$H$G$O$J$/!"%V%m%C%/$r0lEY$G$b(B
|$B<B9T$9$k$H$=$N;~$N(Brefinement$B$N>uBV$r3P$($F$*$$$F!"0c$&>uBV$G<B9T$7$?(B
|$B;~$K%(%i!<$K$9$k$H$$$&M}2r$G9g$C$F$$$k$G$7$g$&$+(B?

$B$O$$!#(B

|$B%$%s%i%$%s%-%c%C%7%e$NLdBj$K$D$$$F$O!"[email protected]$5$s$N0F$G2r7h$5$l$=$&(B
|$B$G$9$,!"$=$l$G$b!V(Brefinement$B>uBV$,0[$J$k>uBV$G$N%V%m%C%/$N<B9T$O6X;_!W(B
|$B$7$?J}$,$h$$$H;W$o$l$^$9$+(B?
|$B;EMME*$K$A$g$C$HHyL/$J5$$,$9$k$N$G$9$,!#(B

$B3N$+$K$A$g$C$HF|OB$C$?0F$+$b$7$l$^$;$s!#CfESH>C<$J;EMM$O$d$a(B
$B$F!“6X;_$+5v2D$+$$$:$l$+$G$”$k$Y$-$G$7$g$&$+!#;H$$>!<j$H$7$F(B
$B$O5v2D$7$?$[$&$,05E]E*$K;H$$$d$9$$$G$7$g$&$,!#(B

                            $B$^$D$b$H(B $B$f$-$R$m(B /:|)

$BA0ED$G$9!#(B

2012$BG/(B11$B7n(B12$BF|(B 22:23 Yukihiro M. [email protected]:

|$B%$%s%i%$%s%-%c%C%7%e$NLdBj$K$D$$$F$O!"[email protected]$5$s$N0F$G2r7h$5$l$=$&(B
|$B$G$9$,!"$=$l$G$b!V(Brefinement$B>uBV$,0[$J$k>uBV$G$N%V%m%C%/$N<B9T$O6X;_!W(B
|$B$7$?J}$,$h$$$H;W$o$l$^$9$+(B?
|$B;EMME*$K$A$g$C$HHyL/$J5$$,$9$k$N$G$9$,!#(B

$B3N$+$K$A$g$C$HF|OB$C$?0F$+$b$7$l$^$;$s!#CfESH>C<$J;EMM$O$d$a(B
$B$F!“6X;_$+5v2D$+$$$:$l$+$G$”$k$Y$-$G$7$g$&$+!#;H$$>!<j$H$7$F(B
$B$O5v2D$7$?$[$&$,05E]E*$K;H$$$d$9$$$G$7$g$&$,!#(B

instance_eval/module_eval$B$K$h$k(Bself$B$NJQ99$K$D$$$F$O$=$N$h$&$J%A%’%C%/$O(B
$B$"$j$^$;$s$,!“[email protected]$H$7$F$OF1$8$h$&$J$b$N$J$N$G!”(Bmodule_eval
$B$K$h$k(Brefinements$B$NM-8z2=$r5v$9$N$G$"$l$P%A%’%C%/$O$J$$J}$,$h$$$H;W$$$^$9!#(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs