Issue #12514 has been updated by Shugo Maeda.


Tiago Cardoso wrote:
> Don't get me wrong, but you're trying to explain me why it doesn't work. I'm making the point it should work. Why?
> 
> If I reopen the string class and include the extensions module, it just works. This is the expected meta-behaviour, as both methods are added to the scope, and lookup is resolved in runtime. 
> 
> This doesn't work with Refinements, and I categorize it as a bug. Infact, I effectively can't use it. Imagine I write a library with a module which injects methods in a core class. In a pre-refinement world, I'll just include the module in runtime and live and dy by the monkey-patch everywhere this core class is used. If I could limit the inclusion with refinements, I'd safely compartimentalize the behaviour injection. I could also provide support for ruby <2 this way. The way this is currently implemented, it's a bit unusable.

I you don't like the current behavior, please file another ticket as a feature request.

A feature called local rebinding, which was rejected by Matz in the past, would solve your problem.
I'm not sure whether it can be solved without local rebinding.


----------------------------------------
Bug #12514: Refinements: when including Module as refinement, can't call other module methods
https://bugs.ruby-lang.org/issues/12514#change-59401

* Author: Tiago Cardoso
* Status: Rejected
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
Very simple script which reproduces the problem:

<pre>
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
    # this doesn't work
    include Extensions
    # this would work...
    # def vegetables ; potatoe ; end
    # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in `<main>': undefined method `vegetables' for "tomatoe":String 
</pre>

failing from ruby 2.0 to 2.3



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>