Hi,

In message "Re: [ruby-core:50355] [ruby-trunk - Feature #4085] Refinements and nested methods"
    on Fri, 30 Nov 2012 10:43:04 +0900, "trans (Thomas Sawyer)" <transfire / gmail.com> writes:

|Then I'd say they refined the wrong class. They should have refined Fixnum. If refining Integer somehow places the refinement in front of Fixnum, then I think all sorts of craziness might ensue.

Otherwise the refinement will be more fragile.  Fixnum is
implementation detail. For example:

  class Foo
  end
  class FooImpl < Foo
  end
  class FooImpl2 < Foo
  end

# FooImpl and FooImpl2 are implementation detail

  module X
    refine Foo do
      def x; ...; end
    end
  end

# we want to intercept method x of class X (and its subclasses).
# we don't want to step in to implementation detail, if possible.

|  # foo.rb library
|  class A
|    def x(i); i; end
|  end
|  class B < A
|    def x(i); super ** 2; end
|  end
|
|  A.new.x(3)  #=> 3
|  B.new.x(3)  #=> 9
|
|  # bar.rb
|  require 'foo'
|  
|  module Moo
|    refine A do
|      def x(i); super + 1; end
|    end
|  end
|
|  using Moo
|
|  A.new.x(3)  #=> 4
|  B.new.x(3)  #=> 10  # not 16!?

Some may expect 10, and others may expect 16.  We cannot satisfy them
all at once.  It's matter of design choice.

							matz.