From: Yehuda Katz Date: 2009-09-02T12:47:51+09:00 Subject: [ruby-core:25256] Re: Module#prepend and Array#prepend --00c09f8de53148d1880472902166 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Sep 1, 2009 at 5:37 PM, David A. Black wrote: > Hi -- > > > On Tue, 1 Sep 2009, Yehuda Katz wrote: > > >> >> On Mon, Aug 31, 2009 at 4:09 AM, David A. Black >> wrote: >> Hi -- >> >> On Mon, 31 Aug 2009, Yehuda Katz wrote: >> >> >> >> On Sun, Aug 30, 2009 at 10:09 PM, Joel VanderWerf >> >> wrote: >> Yehuda Katz wrote: >> class Person >> prepend Exclaimer >> end >> >> >> Is there some way to make the relationship more >> visually obvious? >> >> class Person > Exclaimer >> end >> >> class Person >> self >> Exclaimer >> end >> >> >> Hmmm... seems potentially a bit visually confusing. >> I'm happy with prepend, >> in particular if we also make prepend a method on >> Array. >> >> >> I like the idea of the reverse #include but I'm not sure about the >> name. The problem, for me, is that it's *too* array-like. The other >> related operations don't have that same spatial/collection feel to >> them. Somehow prepend doesn't sound like it's in the same semantic >> space as include. >> >> Now I'm supposed to pony up a brilliant alternative :-) include! came >> to mind. The "dangerous" aspect is that it occludes the current >> version of the method. >> >> module M >> def x >> end >> end >> >> class C >> def x >> end >> >> include M # doesn't affect instances >> include! M # blocks this class's same-named methods >> end >> >> Mind you, I've always been intrigued by the idea of ancestors being >> a fully read-write array. But the current semantics of include are not >> very array-like, so I'm not sure about "prepend". >> >> >> We asked Matz about that, and he felt it was a bit *too* much. One major >> problem is that it would affect classes and not just modules, with more >> dubious semantics. >> > > True. > > One question about the prepend idea: > > module M > def x; "M's x"; end > end > > module N > def x; "N's x"; end > prepend M # or whatever it's called :-) > end > > class C > include N > end > > Would N have sacrificed itself, so to speak, to M, so that: > > C.new.x > > would print "M's x"? Yep. But keep in mind that M could call super, which would go to N's x. -- Yehuda > > > > David > > -- > David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com > Ruby/Rails training, mentoring, consulting, code-review > Latest book: The Well-Grounded Rubyist (http://www.manning.com/black2) > > September Ruby training in NJ has been POSTPONED. Details to follow. > -- Yehuda Katz Developer | Engine Yard (ph) 718.877.1325 --00c09f8de53148d1880472902166 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Tue, Sep 1, 2009 at 5:37 PM, David A.= Black <dblack@r= ubypal.com> wrote:
Hi --


On Tue, 1 Sep 2009, Yehuda Katz wrote:



On Mon, Aug 31, 2009 at 4:09 AM, David A. Black <dblack@rubypal.com> wrote:
=A0 =A0 =A0Hi --

=A0 =A0 =A0On Mon, 31 Aug 2009, Yehuda Katz wrote:



=A0 =A0 =A0 =A0 =A0 =A0On Sun, Aug 30, 2009 at 10:09 PM, Joel VanderWerf =A0 =A0 =A0 =A0 =A0 =A0<vjoel@path.berkeley.edu>
=A0 =A0 =A0 =A0 =A0 =A0wrote:
=A0 =A0 =A0 =A0 =A0 =A0=A0 =A0 =A0Yehuda Katz wrote:
=A0 =A0 =A0 =A0 =A0 =A0=A0 =A0 =A0 =A0 =A0 =A0class Person
=A0 =A0 =A0 =A0 =A0 =A0=A0 =A0 =A0 =A0 =A0 =A0=A0prepend Exclaimer
=A0 =A0 =A0 =A0 =A0 =A0=A0 =A0 =A0 =A0 =A0 =A0end


=A0 =A0 =A0 =A0 =A0 =A0Is there some way to make the relationship more
=A0 =A0 =A0 =A0 =A0 =A0visually obvious?

=A0 =A0 =A0 =A0 =A0 =A0class Person > Exclaimer
=A0 =A0 =A0 =A0 =A0 =A0end

=A0 =A0 =A0 =A0 =A0 =A0class Person
=A0 =A0 =A0 =A0 =A0 =A0=A0self >> Exclaimer
=A0 =A0 =A0 =A0 =A0 =A0end


=A0 =A0 =A0 =A0 =A0 =A0Hmmm... seems potentially=A0a bit=A0visually confus= ing.
=A0 =A0 =A0 =A0 =A0 =A0I'm happy with prepend,
=A0 =A0 =A0 =A0 =A0 =A0in particular if we also make prepend a method on =A0 =A0 =A0 =A0 =A0 =A0Array.


I like the idea of the reverse #include but I'm not sure about the
name. The problem, for me, is that it's *too* array-like. The other
related operations don't have that same spatial/collection feel to
them. Somehow prepend doesn't sound like it's in the same semantic<= br> space as include.

Now I'm supposed to pony up a brilliant alternative :-) include! came to mind. The "dangerous" aspect is that it occludes the current version of the method.

=A0module M
=A0 =A0def x
=A0 =A0end
=A0end

=A0class C
=A0 =A0def x
=A0 =A0end

=A0 =A0include M =A0 =A0 =A0 # doesn't affect instances
=A0 =A0include! M =A0 =A0 =A0# blocks this class's same-named methods =A0end

Mind you, I've always been intrigued by the idea of ancestors being
a fully read-write array. But the current semantics of include are not
very array-like, so I'm not sure about "prepend".


We asked Matz about that, and he felt it was a bit *too* much. One major problem is that it would affect classes and not just modules, with more
dubious semantics.

True.

One question about the prepend idea:

=A0module M
=A0 =A0def x; "M's x"; end
=A0end

=A0module N
=A0 =A0def x; "N's x"; end
=A0 =A0prepend M =A0 # or whatever it's called :-)
=A0end

=A0class C
=A0 =A0include N
=A0end

Would N have sacrificed itself, so to speak, to M, so that:

=A0C.new.x

would print "M's x"?

Yep. But= keep in mind that M could call super, which would go to N's x.

-- Yehuda
=A0



David

--
David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com
Ruby/Rails training, mentoring, consulting, code-review
Latest book: The Well-Grounded Rubyist (http://www.manning.com/black2)

September Ruby training in NJ has been POSTPONED. Details to follow.
<= /div>



--
Yehuda Katz
Dev= eloper | Engine Yard
(ph) 718.877.1325
--00c09f8de53148d1880472902166--