Module duplicate

e$B!!$5$5$@$G$9!#e(B

e$B!!$$$D$N$^$K$+e(B 1.9 e$B$G$Oe(B Module e$B$re(B include
e$B$7$?$H$-!"e(Bancestors e$B$KF1$8%be(B
e$B%8%e!<%k$,=E$J$k$h$&$K$J$C$F$$$^$7$?!#e(B

########################
module M
end

class C1
include M
end

class C2 < C1
include M
end

p C2.ancestors
#=>
1.8 : [C2, C1, M, Object, Kernel]
1.9 : [C2, M, C1, M, Object, Kernel, BasicObject]
M e$B$,e(B2e$B2s8=$l$ke(B
########################

e$B!!7k9=Bg$-$JJQ99$@$H;W$&$N$G$9$,!"$3$N;EMM$K$D$$$F2?$+0U8+$,$"$kJ}$O$$$^e(B
e$B$;$s$+!#e(B

e$B!!F3F~$NM}M3$O!"e(Binclude
e$B$7$?$3$H$r$7$C$+$j$H1F6A$rM?$($k$?$a!J>e5-Nc$G$Oe(B
C2 e$B$Ge(B M e$B$re(B include e$B$7$?$i!“e(BC2 e$B$N%a%=%C%Ie(B m
e$B$h$j@h$Ke(B M e$B$N%a%=%C%Ie(B m e$B$,8Fe(B
e$B$P$l$FM_$7$$!”$H$+!K$H$$$&$3$H$G$9!#e(B

e$B!!$,!“8D?ME*$K$OF1$8%a%=%C%I$,e(B super e$B$K$h$C$Fe(B 2
e$B2s0J>e8F$P$l$F$7$^$&$N$Oe(B
e$B$I$&$+$J!”$H;W$C$F$$$^$9!#8F$P$l$F$bA3$k$Y$-!)e(B

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

SASADA Koichi wrote:

e$B!!$$$D$N$^$K$+e(B 1.9 e$B$G$Oe(B Module e$B$re(B include e$B$7$?$H$-!"e(Bancestors e$B$KF1$8%be(B
e$B%8%e!<%k$,=E$J$k$h$&$K$J$C$F$$$^$7$?!#e(B
(snip)
1.9 : [C2, M, C1, M, Object, Kernel, BasicObject]
M e$B$,e(B2e$B2s8=$l$ke(B
########################

e$B!!7k9=Bg$-$JJQ99$@$H;W$&$N$G$9$,!"$3$N;EMM$K$D$$$F2?$+0U8+$,$"$kJ}$O$$$^e(B
e$B$;$s$+!#e(B

Me$B$,e(B2e$B2s8=$l$k$N$O5$;}$A0-$$$H;W$&$N$G$9$,!"e(B

e$B!!F3F~$NM}M3$O!"e(Binclude e$B$7$?$3$H$r$7$C$+$j$H1F6A$rM?$($k$?$a!J>e5-Nc$G$Oe(B
C2 e$B$Ge(B M e$B$re(B include e$B$7$?$i!“e(BC2 e$B$N%a%=%C%Ie(B m e$B$h$j@h$Ke(B M e$B$N%a%=%C%Ie(B m e$B$,8Fe(B
e$B$P$l$FM_$7$$!”$H$+!K$H$$$&$3$H$G$9!#e(B

e$B$H$$$&$3$H$@$H!"B>$NA*Br;h$Oe(B

[C2, M, C1, Object, Kernel, BasicObject]

e$B$K$J$k$N$G$7$g$&$+!#e(B

e$B!!$,!“8D?ME*$K$OF1$8%a%=%C%I$,e(B super e$B$K$h$C$Fe(B 2 e$B2s0J>e8F$P$l$F$7$^$&$N$Oe(B
e$B$I$&$+$J!”$H;W$C$F$$$^$9!#8F$P$l$F$bA3$k$Y$-!)e(B

e$B;d$be(B2e$B2s0J>e8F$P$l$k$N$O$A$g$C$H$I$&$+$J$H;W$$$^$9!#e(B
e$B$?$@!"e(B

[C2, M, C1, Object, Kernel, BasicObject]

e$B$_$?$$$J=gHV$K$9$k$H!"e(BC1e$B$,e(BMe$B$N%a%=%C%I$re(Bsupere$B$G8F$V$3$H$r0U?^$7$F$$$?e(B
e$B>l9g$KF0:n$7$J$/$J$j$=$&$G$9$M!#e(B
e$B$J$N$G!“e(B1.8e$B$N5sF0$NJ}$,9%$^$7$$$h$&$J5$$,$9$k$N$G$9$,!”$3$NJQ99$,860xe(B
e$B$GF0$+$J$/$J$C$F$$$k%3!<%I$,$J$$$N$J$i!“LdBj$J$$$N$+$J$”!#e(B

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

In message “Re: [ruby-dev:29849] Re: Module duplicate”
on Mon, 6 Nov 2006 10:14:12 +0900, Shugo M. [email protected]
writes:

|Me$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!"e(B

module M1
end
module M2
include M1
end
module M3
include M1
end
class C1
include M2
end
class C2<C1
include M3
end

e$B$N$h$&$J%1!<%9$@$H!"FC$Ke(BM3e$B$He(BM1e$B$N4V$K$$$m$$$mF~$k$3$H$N4r$7$/e(B
e$B$J$5$,L\N)$A$=$&$G$9!#e(B

e$B$G!“F0$+$J$/$J$k%3!<%I$,$”$k$+$I$&$+$G$9$,!“e(Btest/unite$B$N0lIte(B
e$B$,F0$+$J$/$J$C$?$N$G!”<j$rF~$l$^$7$?!#$=$l0J30$K$OBg$-$JLdBje(B
e$B$OL5$+$C$?$h$&$G$9!#e(B

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

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

In message “Re: [ruby-dev:29851] Re: Module duplicate”
on Mon, 6 Nov 2006 10:56:18 +0900, Shugo M. [email protected]
writes:

|> # e$BA0ED$/$s8~$1$N@bL@e(B:
|> # (e$B%3%T!<$7$J$$$1$Ie(B)Sathere$B$Ne(Binlcudee$B$G$"$k$H;W$($P5$;}$A0-$/e(B
|> # e$B$J$$$+$b!#e(B
|
|# Sathere$B$O%3%T!<$G$9$7!"e(Bsupere$B$b$J$$$G$9$+$i$M$(!#e(B

e$B$^$“!”$=$&$G$9$M!#e(B

|e$B$G$bF1$8%a%=%C%I$,Fs2s8F$P$l$k$N$O$I$&$J$N$+$J$"!#e(B

e$BF1$8%a%=%C%I$,8F$P$l$k%1!<%9$O$"$^$jB?$/$J$$$G$7$g$&!#e(B

class Root
def foo
p :root
end
end
module M
def foo
super
p :M
end
end
class C1 < Root
include M
def foo
super
p :C1
end
end
class C2 < C1
include M
def foo
super
p :C2
end
end

e$B$N$h$&$J?M9)E*$J%1!<%9$,<+A3$KH/@8$9$k$3$H$OLGB?$K$J$$$H;W$$e(B
e$B$^$9!#$^$?!"$=$l$>$l$NMW5a$r%%/%m$K@Q$>e$2$k$He(B

C2 Me$B$Ge(Bincludee$B$7$?e(Bfooe$B$r8F$S$?$$e(B
C1 Me$B$Ge(Bincludee$B$7$?e(Bfooe$B$r8F$S$?$$e(B
M e$BAH$_9~$^$l$?%/%i%9$N?F%/%i%9$Ne(Bfooe$B$,8F$S$?$$e(B
Root e$B4pK$H$J$ke(Bfooe$B$rDs6!e(B

e$B$H$J$j$^$9$+$i!“$`$7$mFsEY8F$P$l$k$[$&$,<+A3$K8+$($F$-$^$;$se(B
e$B$+!)e(B e$B6l$7$$$+$J$”!#e(B

|e$B6/$$$F$$$($P!"$5$5$@$5$s$N:n6H$X$N1F6A$,5$$K$J$k$3$H$/$i$$$G$9$,!"e(B
|e$B$5$5$@$5$s$b7h$^$C$F$7$^$($P$o$j$H$I$C$A$G$b$$$$$s$G$7$g$&$+!#e(B

e$B$$$d!"7Q>5%i%$%s$KF1$8%b%8%e!<%k$,FsEYEP>l$9$k$N$O$+$J$jCWL?e(B
e$BE*$i$7$$$G$9$h!#$3$NJU$,;d$H$7$F$b6/$/<gD%$7$K$/$$$H$3$m!#e(B

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

e$B!!$5$5$@$G$9!#e(B

Yukihiro M. wrote:

|# Sathere$B$O%3%T!<$G$9$7!"e(Bsupere$B$b$J$$$G$9$+$i$M$(!#e(B

e$B$^$"!"$=$&$G$9$M!#e(B

e$B!!e(BModule e$B$N%a%=%C%I$G$Oe(B super
e$B$rL5$/$9$C$F$N$b8=<BE*$8$c$J$$$G$9$h$M$’!#e(B

|e$B$G$bF1$8%a%=%C%I$,Fs2s8F$P$l$k$N$O$I$&$J$N$+$J$"!#e(B

e$BF1$8%a%=%C%I$,8F$P$l$k%1!<%9$O$"$^$jB?$/$J$$$G$7$g$&!#e(B

e$B!!<B:]$K$"$C$?%1!<%9$H$7$F!“e(BRSS e$B$,$”$j$^$7$?!#e(B

require ‘rss’
rss_version = ‘2.0’
version = “1.0”
encoding = “UTF-8”
standalone = false
rss = RSS::Rss.new(@rss_version, version, encoding, standalone)
p rss.class.ancestors

#=> [RSS::Rss, RSS::XMLStyleSheetMixin, RSS::RootElementMixin,
RSS::XMLStyleSheetMixin, RSS::RSS09, RSS::Element, RSS::Utils, Object,
Kernel, BasicObject]

e$B$G!"e(BXMLStyleSheetMixin#initialize e$B$H$+$,e(B super
e$B$7$F$^$9!#$h$/$o$+$s$J$$e(B
e$B$1$IF0$$$F$k$N$G!"LdBj$O$J$$$N$+$b$7$l$^$;$s!#e(B

e$B!!B?J,!“I]$$$N$O5$$E$+$J$$4V$KF1$8%b%8%e!<%k$re(B include
e$B$7$A$c$C$F!“0U?^e(B
e$B$;$:$KJ#?t2s8F$S=P$7$F$7$^$&!”$C$F$$$&$3$H$@$H;W$$$^$9!#$,!”$A$c$s$H5$$re(B
e$B$D$1$m$C$F$3$H$J$N$+$b$7$l$^$;$s!#e(B

e$B$H$J$j$^$9$+$i!"$`$7$mFsEY8F$P$l$k$[$&$,<+A3$K8+$($F$-$^$;$se(B
e$B$+!)e(B e$B6l$7$$$+$J$"!#e(B

e$B!!<+A3$+$b$7$l$^$;$s!#B>$N8@8l$N;vNc!“BP=h$J$I$b!”$b$7$"$l$P8+$F$_$?$$$G$9!#e(B

|e$B6/$$$F$$$($P!"$5$5$@$5$s$N:n6H$X$N1F6A$,5$$K$J$k$3$H$/$i$$$G$9$,!"e(B
|e$B$5$5$@$5$s$b7h$^$C$F$7$^$($P$o$j$H$I$C$A$G$b$$$$$s$G$7$g$&$+!#e(B

e$B$$$d!"7Q>5%i%$%s$KF1$8%b%8%e!<%k$,FsEYEP>l$9$k$N$O$+$J$jCWL?e(B
e$BE*$i$7$$$G$9$h!#$3$NJU$,;d$H$7$F$b6/$/<gD%$7$K$/$$$H$3$m!#e(B

e$B!!<BAu$K0z$-$:$i$l$J$$$N$,e(B Ruby
e$B$NFCD’$@$H;W$&$N$G!"$3$&$9$k$Y$-!"$H$$$&e(B
e$B7kO@$K$J$C$?$iD>$7$^$9!#$?$@!"!V$I$C$A$G$b$$$$$1$I!J$I$C$A$,$$$$$+$h$/$oe(B
e$B$+$s$J$$$1$I!K$3$C$A$N$[$&$,$$$$$+$b!)!W$H$+$@$C$?$i<BAu$r5$$K$7$FM_$7$$e(B
e$B$J$"$H8@$&5$$,$7$^$9!#e(B

e$B!!$5$5$@$G$9!#e(B

SASADA Koichi wrote:

#=> [RSS::Rss, RSS::XMLStyleSheetMixin, RSS::RootElementMixin,
RSS::XMLStyleSheetMixin, RSS::RSS09, RSS::Element, RSS::Utils, Object,
Kernel, BasicObject]

e$B$G!"e(BXMLStyleSheetMixin#initialize e$B$H$+$,e(B super e$B$7$F$^$9!#$h$/$o$+$s$J$$e(B
e$B$1$IF0$$$F$k$N$G!"LdBj$O$J$$$N$+$b$7$l$^$;$s!#e(B

e$B!!$&$%$`!#?\F#$5$s$,D>$7$F$/$l$?$N$G!"e(BYARV
e$B$G$b%F%9%H$,$9$s$J$jDL$k$h$&e(B
e$B$K$J$j$^$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$BA0ED$G$9!#e(B

Yukihiro M. wrote:

|Me$B$,e(B2e$B2s8=$l$k$N$O5$;}$A0-$$$H;W$&$N$G$9$,!"e(B

e$B$=$l$O<g4Q$J$s$G$A$g$C$HCV$$$H$$$F!#e(B

e$BA0ED$/$s8~$1$N@bL@e(B:

(e$B%3%T!<$7$J$$$1$Ie(B)Sathere$B$Ne(Binlcudee$B$G$"$k$H;W$($P5$;}$A0-$/e(B

e$B$J$$$+$b!#e(B

Sathere$B$O%3%T!<$G$9$7!"e(Bsupere$B$b$J$$$G$9$+$i$M$(!#e(B

e$B$3$l$O$"$j$($J$$$H;W$$$^$9!#e(BC1e$B$,e(BMe$B$K0MB8$7$F$?$iF0$+$J$/$J$je(B
e$B$^$9$+$i!#e(B

e$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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$B3HD%L5$7$N>uBV$KJQ99$9$k$?$a$K!$e(Binclude
    ExtA/ExtBe$B$@$1$G$O$J$/e(B
    include ExtBasee$B$b%3%a%s%H%"%&%H$7$J$1$l$P$$$1$J$$$N$,<j4V!%e(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