Issue #14344 has been updated by palkan (Vladimir Dementyev).


shevegen (Robert A. Heiler) wrote:
> I think that:
> 
>     using do
>       refine Array do 
> 
> Is not good. It looks very strange to me.

On the other hand, it's closer to what we have to write now (`using(Module.new do`) and it doesn't have any additional constraints like being at the top level of class/module context dependent.

> 
> The other variants, such as the original one:
> 
>     class Test
>       refine String do
> 

The problem with this approach has been already mentioned by Benoit  ([[https://bugs.ruby-lang.org/issues/14344#note-7]]): the behaviour of `refine` changes depending on whether we're in the module or class context.

IMO, it would introduce even more confusion. And the goal of this feature, as it has been said, is to lower the barrier.

> (On a side note, I think you added it to the recent developer meeting
> which already happened)

Oops, I got lost in time) thanks for noticing!

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-76248

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



-- 
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>