e$B?\F#$G$9!%e(B
06/11/06 e$B$Ke(B SASADA Koichi[email protected] e$B$5$s$O=q$-$^$7$?e(B:
e$B$3$l$O!“$I$&H=CG$9$k$Y$-$G$9$+$M!#:#2s$_$?$$$KBP1~$9$k$Y$-LdBj$J$N$+!“e(B
e$B;EMM$,A0$NJ}$,$$$$$N$+!#?\F#$5$s!”$3$l$K$D$$$F$J$s$+0U8+$”$j$^$;$s$+!)e(B
e$B;d$O!$F1$8%a%=%C%I$,e(B2e$B2s8F$P$l$k$N$,5$;}$A0-$$$N$G:#$^$G$N;EMM$NJ}$,e(B
e$B$$$$$G$9!%$?$@!$e(B1.9e$B$N;EMM$G$be(B2e$B2s8F$P$l$J$$$h$&$K%=!<%9%3!<%I$r!J$*$=e(B
e$B$i$/4JC1$K!K=$@5$G$-$k$H;W$&$N$G!$$=$s$J$K6/$/<gD%$G$-$J$$$G$9!%e(B
e$B:#$^$G$N;EMM$@$H4r$7$$%3!<%INc$r$“$2$^$9!%%”%W%j%1!<%7%g%s%/%i%9$K!$e(B
Modulee$B$re(Bincludee$B$7$F$$$/$3$H$K$h$C$F5!G=$rDI2C$7$F$$$/!$$H$$$&$N$rA[Dje(B
e$B$7$F$$$^$9!%e(B
module ExtBase
attr_reader :exts
#
Modulee$B$Ge(Binitializee$B$rDj5A$9$k$H$-$O$I$3$K64$^$C$F$b$$$$$h$&$Ke(B
# e$B0z?t$r4]Ej$2$7$F<+J,$NJ,$r=i4|2=$9$k%3!<%I$r=q$/$3$H$,B?$$e(B
# e$B$G$9!%e(B
def initialize(*args, &block)
super
@exts = []
end
end
module ExtA
include ExtBase
def initialize(*args, &block)
super
@exts << :a
end
end
module ExtB
include ExtBase
def initialize(*args, &block)
super
@exts << :b
end
end
class Base
def initialize(…)
…
end
end
class App < Base
include ExtA
include ExtB
def initialize(...)
super
...
end
end
1.9e$B$@$H$3$&$J$k$s$G$9$h$M!)e(B
p App.new.exts # => [:b]
e$B$=$7$F!$$*$=$i$/$3$N$h$&$KJQ99$9$l$P$h$$$N$G$9$h$M!)e(B
module ExtA
def initialize(*args, &block)
super
@exts << :a
end
end
module ExtB
def initialize(*args, &block)
super
@exts << :b
end
end
class App < Base
include ExtBase
include ExtA
include ExtB
def initialize(...)
super
...
end
end
e$B;d$O=q$-D>$7$?$d$D$h$j$b!$=q$-D>$9A0$N$d$D$NJ}$,9%$-$G$9!%M}M3$Oe(B
ExtBasee$B$K0MB8$7$F$$$k$N$Oe(BExtAe$B$He(BExtBe$B$J$N$G!$e(Bincludee$B$Oe(BAppe$B$8$c$J$/$Fe(B
e$B$=$C$A$K=q$-$?$$e(B
e$B$+$i$G$9!%e(B
e$B>C6KE*$JM}M3$O0J2<$NDL$j$G$9!%e(B
ExtA/ExtBe$B$r;H$&$?$a$K$O;vA0$Ke(BExtBasee$B$re(Bincludee$B$7$F$*$/I,MW$,$"$k$He(B
e$B$$$&$N$O!$K:$l$F$7$^$$$=$&$G7y!%e(B #
e$B%I%-%e%a%s%H$G$J$s$H$G$b$J$ke(B
e$B5U$K!$3HD%L5$7$N>uBV$+$i3HD%5!G=e(BAe$B$rDI2C$9$k$?$a$K!$e(Binclude
ExtA
e$B$@$1$8$c$J$/!$e(Binclude
ExtBasee$B$b=q$+$J$1$l$P$$$1$J$$$N$,7y!%e(B
Modulee$B$G$Ne(Bsupere$B6X;_$O>iCL$@$H;W$$$^$9$,!$0l1~!$6/$/H]Dj$7$F$$-$^$9!%e(B
e$BM}M3$O>e5-$N$h$&$Je(BModulee$BKh$K=i4|2=$9$k$H$$$&$h$&$J>l9g!$e(Bincludee$B$9$k%/e(B
e$B%i%9B&$GL@<(E$K3Fe(BModulee$B$N=i4|2=%a%=%C%I$r8F$S=P$9$H$$$C$?$3$H$r$7$Je(B
e$B$1$l$P$J$/$J$k$+$i$G$9!%e(B
module ExtA
def init_ext_a
…
end
end
module ExtB
def init_ext_b
…
end
end
class App
def initialize
…
init_ext_a
init_ext_b
end
end