From: SASADA Koichi <ko1@...>
Date: 2012-11-04T01:42:55+09:00
Subject: [ruby-core:48810] Re: [ruby-trunk - Bug #7269] Refinement doesn't work if using locate after method

(2012/11/03 10:36), SASADA Koichi wrote:
> (2012/11/03 10:11), headius (Charles Nutter) wrote:
>> I don't like the idea that using should affect methods already defined. At this point I view using similar to private/protected/etc, which also do not affect methods defined before you call them.
> 
> I feel that `using' is similar to `include' and `prepend' rather than
> `public' and `private'.
> 

The following code (C_User2#x) affect refinement `after' defining
method. Is that intentional?


###

class C
  def foo
    p :C_foo
  end
end

module RefineC
  refine C do
    def foo
      p :RefineC_foo
      super
    end
  end
end

class C_User
  using RefineC
  def x
    C.new.foo
  end
end

class C_User2
  def x
    self.class.send(:using, RefineC)
    C.new.foo
  end
end

puts "C.new.foo"
C.new.foo

puts "C_User.new.x"
C_User.new.x

puts "C_User2.new.x"
C_User2.new.x


#=>
C.new.foo
:C_foo
C_User.new.x
:RefineC_foo
:C_foo
C_User2.new.x
:RefineC_foo
:C_foo


-- 
// SASADA Koichi at atdot dot net