I think that, for this same reason, `using` should normally not apply
outside of the immediate lexical scope. I actually believed that this was
the default behavior, and explained why I thought it was a good idea on my
blog (http://yehudakatz.com/2010/11/30/ruby-2-0-refinements-in-practice/).

In general, the most utility from refinements comes from being able to use
them freely, without worrying about accidentally breaking other code. In the
case of subclasses, for instance, I would want to be able to add a
refinement in a Rails 3.0.3 class (like ActionController::Base) for
convenience without worrying about breaking existing Rails apps that don't
expect core classes to suddenly change behavior.

I can understand the utility of offering the inherited style when desired,
but I don't think it should be the default. By default, the principle of
this feature requires that refinements modify zero code outside its lexical
scope.

Perhaps a special form of using that would also affect subclasses (for
example, for the case where Rails wants to expose ActiveSupport into its
subclasses):

class ActionController::Base
  using ActiveSupport, inherited: true
end

Yehuda Katz
Architect | Strobe
(ph) 718.877.1325


On Mon, Dec 6, 2010 at 12:12 AM, Shugo Maeda <shugo / ruby-lang.org> wrote:

> Hi,
>
> 2010/12/5 Yukihiro Matsumoto <matz / ruby-lang.org>:
> > I am neutral about local rebinding.  It is useful sometimes (as
> > someone has pointed out in this thread).  At the same time, I agree
> > with you that performance impact is a huge negative factor against
> > local rebinding.  We need more input.  Dave, what do you think?
> > Anyone else?
>
> I believe we should not support local rebinding.
>
> I guess local rebinding is not designed for refinements of classes
> which have many clients like built-in classes.  With local rebinding,
> when we refine a built-in class such as String, we have to take care
> carefully not to break existing code.  This means that, it's
> ridiculous to use the following refinement with local rebinding.
>
>  module MathN
>     refine Fixnum do
>      def /(other) quo(other) end
>    end
>  end
>
> My intention is to bring modularity into monkey patching, not to bring
> extensibility.  We already have enough extensibility in Ruby.
>
> --
> Shugo Maeda
>
>