From: Trans Date: 2012-11-15T08:24:15+09:00 Subject: [ruby-core:49350] Re: [ruby-trunk - Feature #4085] Refinements and nested methods --f46d04426cd022097e04ce7cd56e Content-Type: text/plain; charset=UTF-8 Perhaps refinements should be scoped per-gem, rather than any arbitrary "using" delimitation. Seems to me, that is generally the level at which we care about them. Would that simplify implementation and comprehensibility of usage to something more manageable? On Wed, Nov 14, 2012 at 1:35 PM, Aaron Patterson wrote: > On Wed, Nov 14, 2012 at 05:38:12AM +0900, headius (Charles Nutter) wrote: > > [snip] > > > And then there's this: > > > > class Foo < SomeParent > > def baz(str) > > ary.map {|name| str.camelize + name} > > end > > end > > > > In this case, you have to check even more places for refinements to know > what methods will be called: > > > > * Foo may have been previously refined. You must look for all reopenings > of Foo to know what will be called. > > * SomeParent or its parents may have been previously refined. You must > look for all reopenings of SomeParent and its parents. > > * The map method may force refinements on the block. you must look for > all implementations of map() that might be called here to see if they force > refinements into the block. > > > > This is supposed to be simpler? > > I have to agree. It seems like this would be *much* more difficult to > debug than if `camelize` is just monkey patched on to String. > > This code: > > class Foo < SomeParent > def baz(str) > cached = str.camelize > ary.map {|name| cached + name} > end > end > > Could have a completely different meaning than this code: > > class Foo < SomeParent > def baz(str) > ary.map {|name| str.camelize + name} > end > end > > That seems extremely bad. > > -- > Aaron Patterson > http://tenderlovemaking.com/ > > -- Sorry, says the barman, we don't serve neutrinos. A neutrino walks into a bar. Trans 7r4n5.com http://7r4n5.com --f46d04426cd022097e04ce7cd56e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Perhaps refinements should be scoped per-gem, rather than any arbitrar= y "using"=C2=A0delimitation. Seems to me, that is generally the l= evel at which we care about them.

Would that simpl= ify implementation and comprehensibility of usage to something more=C2=A0ma= nageable?


On Wed, Nov 1= 4, 2012 at 1:35 PM, Aaron Patterson <tenderlove@ruby-lang.org&g= t; wrote:
On Wed, Nov 14, 2012 at 05:38:12AM +0900, he= adius (Charles Nutter) wrote:

[snip]

> And then there's this:
>
> class Foo < SomeParent
> =C2=A0 def baz(str)
> =C2=A0 =C2=A0 ary.map {|name| str.camelize + name}
> =C2=A0 end
> end
>
> In this case, you have to check even more places for refinements to kn= ow what methods will be called:
>
> * Foo may have been previously refined. You must look for all reopenin= gs of Foo to know what will be called.
> * SomeParent or its parents may have been previously refined. You must= look for all reopenings of SomeParent and its parents.
> * The map method may force refinements on the block. you must look for= all implementations of map() that might be called here to see if they forc= e refinements into the block.
>
> This is supposed to be simpler?

I have to agree. =C2=A0It seems like this would be *much* more difficult to=
debug than if `camelize` is just monkey patched on to String.

This code:

=C2=A0 class Foo < SomeParent
=C2=A0 =C2=A0 def baz(str)
=C2=A0 =C2=A0 =C2=A0 cached =3D str.camelize
=C2=A0 =C2=A0 =C2=A0 ary.map {|name| cached + name}
=C2=A0 =C2=A0 end
=C2=A0 end

Could have a completely different meaning than this code:

=C2=A0 class Foo < SomeParent
=C2=A0 =C2=A0 def baz(str)
=C2=A0 =C2=A0 =C2=A0 ary.map {|name| str.camelize + name}
=C2=A0 =C2=A0 end
=C2=A0 end

That seems extremely bad.

--
Aaron Patterson
http://tenderlov= emaking.com/




-- Sorry, says the barman, we don't serve neutrinos. A neutrino walks in= to a bar.

Trans <transfire@gmail.com>
7r4n5.com=C2=A0 =C2=A0 = =C2=A0 http://7r4n5.com<= br>


--f46d04426cd022097e04ce7cd56e--