From: Trans Date: 2012-11-20T23:40:55+09:00 Subject: [ruby-core:49762] Re: [ruby-trunk - Feature #4085] Refinements and nested methods --14dae934109f9af59904ceee386c Content-Type: text/plain; charset=UTF-8 > This should return nil. Otherwise, refinements can break code which doesn't expect the refined behavior. Ok. Makes sense. > I don't understand why it's worse. Only worse in that case if you had not said `nil`. Since you did say `nil`, then what about: class S def foo "foo" end def bar "bar" end def foobar foo + bar end end module R refine S do def bar "bar!" end end end class C < S using R alias :foobar! :foobar def foobar? foo + bar end def brainfart1 c = C.new c.foobar! == c.foobar? end def brainfart2 c = C.new s = S.new c.foobar! == s.foobar end def brainfart3 c = C.new s = S.new c.bar == s.bar end end C.new.brainfart1 #=> ? C.new.brainfart2 #=> ? C.new.brainfart3 #=> ? --14dae934109f9af59904ceee386c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable > This shoul= d return nil. =C2=A0Otherwise, refinements can break code which doesn't= expect the refined behavior.

Ok. Makes sense.=C2=A0

> I don't understand why it's worse.

Only worse in that case if you had not said `nil`.

Since you did say `nil`, then what about:

=C2=A0 =C2=A0 class S
=C2=A0 =C2=A0= =C2=A0 def foo
=C2=A0 =C2=A0 =C2=A0 =C2=A0 "foo" =C2= =A0 =C2=A0 =C2=A0
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 = =C2=A0 =C2=A0 def bar
=C2=A0 =C2=A0 =C2=A0 =C2=A0 "bar"= =C2=A0 =C2=A0 =C2=A0
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 def foobar
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = foo + bar
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 end

=C2=A0 =C2=A0 module R
=C2=A0 =C2=A0 =C2=A0 refine S do
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 def bar
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "bar!"
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 end

=C2=A0 =C2=A0 class C < S
=C2= =A0 =C2=A0 =C2=A0 using R
=C2=A0 =C2=A0 =C2=A0 alias :foobar! :fo= obar
=C2=A0 =C2=A0 =C2=A0 def foobar?
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 foo + bar
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 def brainfart1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 c =3D C.new
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 c.foobar! =3D=3D c.foobar?
=C2=A0 =C2=A0= =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 def brainfart2
=C2=A0 =C2=A0 =C2=A0 =C2=A0 c =3D C.new
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 s =3D S.new
=C2=A0 =C2=A0 =C2=A0 =C2=A0 c.foobar! =3D= =3D s.foobar
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 def= brainfart3
=C2=A0 =C2=A0 =C2=A0 =C2=A0 c =3D C.new
=C2=A0 =C2=A0 =C2=A0 =C2=A0 s =3D S.new
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 c.bar =3D=3D s.bar
=C2=A0 =C2=A0 =C2=A0 end
<= br>
=C2=A0 =C2=A0 end

=C2=A0 =C2=A0 C.new.brainfart1 =C2=A0#=3D> ?
=C2=A0 =C2=A0 C.new.brainfart2 =C2=A0#=3D> ?
=C2=A0 =C2= =A0 C.new.brainfart3 =C2=A0#=3D> ?

<= div class=3D"gmail_extra">

--14dae934109f9af59904ceee386c--