From: Clay Trump Date: 2012-10-27T05:16:53+09:00 Subject: [ruby-core:48332] Re: [ruby-trunk - Feature #1586] Including a module already present in ancestors should not be ignored --20cf3071cf82172ccd04ccfc00f3 Content-Type: text/plain; charset=ISO-8859-1 I'm looking forward to consistent module inclusion :-) I should have talked about Marc-andre's example with multiple inclusion at the same level (same class/module/object), coz I don't think it should be done this way. The example was: module M def to_s "*" + super + "*" end end 3.times{ Fixnum.prepend(M) } 42.to_s # => "*42*" would be best, not "***42***" My reasoning is that otehrwise it makes it hard to reload a Ruby class definition. When debugging, it is frequent that one modifies a method definition, reloads the whole file and tests away. It would not be practical if any +include+ or +prepend+ in the class definition induced a change in the ancestry. If someone really wants multiple inclusion *at the same level*, it can be achieved by dupping the module. So I believe that a module should only be included once per class/module/object. Same thing for prepending. Prepending and including should be independent though. 3.times{ Fixnum.prepend(M) } 2.times{ Fixnum.include(M) } Numeric.prepend(M) Fixnum.ancestors # => [M, Fixnum, M, M, Numeric, ...], not [M, M, M, Fixnum, M, M, M, Numeric, ...] Is that the plan? Was this brought up when discussing with Matz about this? --20cf3071cf82172ccd04ccfc00f3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I'm looking forward to consistent module inclusion :-)

I should = have talked about Marc-andre's example with multiple inclusion at the s= ame level (same class/module/object), coz I don't think it should be do= ne this way. The example was:

=A0=A0=A0 module M
=A0=A0=A0=A0=A0 def to_s
=A0=A0=A0=A0=A0=A0=A0= "*" + super + "*"
=A0=A0=A0=A0=A0 end
=A0=A0=A0 = end
=A0
=A0=A0=A0 3.times{ Fixnum.prepend(M) }
=A0=A0=A0 42.to_s = # =3D> "*42*" would be best, not "***42***"

My reasoning is that otehrwise it makes it hard to reload a Ruby class = definition. When debugging, it is frequent that one modifies a method defin= ition, reloads the whole file and tests away. It would not be practical if = any +include+ or +prepend+ in the class definition induced a change in the = ancestry.

If someone really wants multiple inclusion *at the same level*, it can = be achieved by dupping the module.

So I believe that a module should= only be included once per class/module/object. Same thing for prepending. = Prepending and including should be independent though.

=A0=A0=A0 3.times{ Fixnum.prepend(M) }
=A0=A0=A0 2.times{ Fixnum.inc= lude(M) }
=A0=A0=A0 Numeric.prepend(M)
=A0=A0=A0 Fixnum.ancestors # = =3D> [M, Fixnum, M, M, Numeric, ...], not [M, M, M, Fixnum, M, M, M, Num= eric, ...]

Is that the plan? Was this brought up when discussing wit= h Matz about this?

--20cf3071cf82172ccd04ccfc00f3--