Hello ruby-core,  

First, thank you to everyone involved in RubyConf! I had a number of good discussions there, and coming from these I would like to humbly propose a potential solution to some of the issues surrounding Modules. What I would propose would be to treat Modules (and subsequently Classes) as "library forms", and to introduce methods Module#only, Module#except, Module#prefix, and Module#rename. These names are not arbitrary, and in fact correlate directly with the methods described for library formsin Scheme's R6RS standard (section 7.1, http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-10.html#node_sec_7.1). Module#prefix and Module#rename are straight-forward, as their names imply.

Module#only takes a list of symbols and returns a Module containing only the matching methods. Module#except takes either another Module or a list of identifiers and would return a Module refined according to the argument. So, for example:

 module A
 def foo; end
 def bar; end
 end
 module B
 include A.only(:foo)
 def baz; end
 end
 #=> module B now contains methods :foo and :baz, but not :bar

These could also be used in combination with shadowing bindings to accomplish much of what refinements intended. For example:

 module A; end
 module B; end
 class String
 include A
 include B
 end

 # laterí─
 class Foo
 String = String.except(A)
 #=> from this point on, any resolution of "String" in this scopewould
 # use the "shadow" String class which contains methods from
 # module B but not any from module A.
 end

I think this should also remove the performance concerns from refinements, as nothing has changed regarding scoping rules or constant look-up. Instead, there would be two "String" classes now: Foo::String and ::String. Thoughts?

- Josh