Issue #9704 has been updated by Thomas Sawyer.


Just FYI, I created this project https://github.com/rubyworks/reusing. I don't much care for what I had to do to implement it, i.e.

* it's not possible to simply override `#using`
* had to use my finder gem to find libraries
* had to use clunky gsub and eval

But it appears to be working.


----------------------------------------
Feature #9704: Refinements as files instead of modules
https://bugs.ruby-lang.org/issues/9704#change-46285

* Author: Thomas Sawyer
* Status: Open
* Priority: Normal
* Assignee: 
* Category: core
* Target version: Next Major
----------------------------------------
If refinements are to remain file-scoped, then it would be more convenient if `using` worked at the file level, akin to `require`, rather than behave like a module `include`. For instance, instead of:

~~~
# foo.rb
module Foo
  refine String do
    def some_method
      ...
    end
  end
end
~~~

~~~
require 'foo'
using Foo
~~~

We could do:

~~~
# foo.rb
class String
  def some_method
    ...
  end
end
~~~

~~~
using 'foo'
~~~

This would make `require` and `using`, in a certain sense, *polymorphic* --if we `require` it will extend the classes directly, but if `using` then they will be refined instead.




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