Hi,

Thanks for you comment.

2010/11/25 Dave Thomas <redmine / ruby-lang.org>:
> =A0module Quux
> =A0 =A0using FooExt
>
> =A0 =A0foo =3D Foo.new
> =A0 =A0foo.bar =A0# =3D> FooExt#bar
> =A0 =A0foo.baz =A0# =3D> Foo#bar
> =A0end
>
> This behavior makes me nervous=97I can see arguments for it, but at the s=
ame time I can see in leading to problems, particularly in well structured =
classes where a large set of behaviors is defined in terms of one method. I=
'm sure the syntax below is wrong, but look at the spirit of it.
>
> =A0module DoubleEach
> =A0 =A0refine Array do
> =A0 =A0 =A0def each
> =A0 =A0 =A0 =A0 super do |val|
> =A0 =A0 =A0 =A0 =A0 yield 2*val
> =A0 =A0 =A0 =A0 end
> =A0 =A0 =A0end
> =A0 =A0end
> =A0end
>
> =A0using DoubleEach
>
> =A0[ 1, 2, 3 ].each {|v| p v } =A0 #=3D> 2, 4, 6
>
> =A0[ 1, 2, 3 ].min =A0 =A0#=3D> 1

The syntax right and currently [1,2,3].min returns 2.
However, It's a bug (methods implemented by C behave wrong),
and I think it should return 1 as you showed above.

> That would be surprising to me, as I'd expect the behavior of all the Enu=
merable methods, which depend on each, to change if I change the behavior o=
f each.

However, some other person might expect the original behavior of each.
For example,

  class Foo
     using DoubleEach

     def bar
       SomeOtherModule.do_something # DoubleEach may break this method
     end
  end

If SomeOtherModule.do_something is implemented by someone else, and
Array#each is used in do_something, DoubleEach breaks the code.
If you'd like to change the behavior of callees, you can use monky
patching or singleton methods instead of refinements.

--=20
Shugo Maeda