[ruby-core:91018] [Ruby trunk Feature#14344] refine at class level

From: shevegen@...
Date: 2019-01-11 11:05:34 UTC
List: ruby-core #91018
Issue #14344 has been updated by shevegen (Robert A. Heiler).


I think that:

    using do
      refine Array do 

Is not good. It looks very strange to me.

The other variants, such as the original one:

    class Test
      refine String do

or just toplevel:

    refine String do

would seem better to me.

It may be best to have matz pick a syntax, if he agrees with the feature. :)

(May have to then also update documentation and specification of 
refinements; I remember that I was once surprised thinking that I 
knew the original definition but upon re-reading it, I realized that 
my assumption was not completely correct.)

(On a side note, I think you added it to the recent developer meeting
which already happened; may have to add it to the next one or
just have it be a carry-over to the next meeting.)

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

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

In This Thread

Prev Next