From: Intransition Date: 2011-12-27T00:01:07+09:00 Subject: Re: Mixin for Mixins ------=_Part_432_25737030.1324911665054 Content-Type: multipart/alternative; boundary="----=_Part_433_6956989.1324911665054" ------=_Part_433_6956989.1324911665054 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On Monday, December 26, 2011 2:33:02 AM UTC-5, Josh Cheek wrote: > > Why do you invoke the included method by including the Extension into > Facets::String? I see this all over the place (esp in Rails) but don't get > why. It's just an ultra fancy way to invoke a method, but it pollutes > String's ancestry and makes it nonobvious what's happening. This code > doesn't also extend in the included hook, but I see that a lot, too (e.g. > > https://github.com/rails/rails/blob/master/activerecord/lib/active_record/model.rb#L17 > ). > Fair point. You might want to pollute String with the CoreExtension mixin. OTOH, it makes it easy to identify that it was extended as such, e.g. String.ancestors => [String, CoreExtension, Comparable, Kernel, BasicObject] And since there are no instance methods in it I don't think it hurts anything. > How about something like this as an alternative: > Actually, if we used #append_features instead of #include, we could prevent the inclusion, but still use `include` to apply the extended features, ------=_Part_433_6956989.1324911665054 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

On Monday, December 26, 2011 2:33:02 AM UTC-5, Josh Cheek wrote:

Why do you invoke the included= method by including the Extension into
Facets::String? I see this all o= ver the place (esp in Rails) but don't get
why. It's just an ultra fancy= way to invoke a method, but it pollutes
String's ancestry and makes it = nonobvious what's happening. This code
doesn't also extend in the includ= ed hook, but I see that a lot, too (e.g.
https://github.com/rails/rails/blob/master/activereco= rd/lib/active_record/model.rb#L17
).


<= /div>
Fair point. You might want to pollute String with the CoreExtensi= on mixin. OTOH, it makes it easy to identify that it was extended as such, = e.g.

  String.ancestors
&n= bsp; =3D> [String, CoreExtension, Comparable, Kernel, BasicObject]
=

And since there are no instance methods in it I d= on't think it hurts anything.
 

How about something like t= his as an alternative:

Actually, if we used #append_fe= atures instead of #include, we could prevent the inclusion, but still use `= include` to apply the extended features,

------=_Part_433_6956989.1324911665054-- ------=_Part_432_25737030.1324911665054--