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

From: kevin.deisz@...
Date: 2018-04-17 15:38:28 UTC
List: ruby-core #86561
Issue #14344 has been updated by kddeisz (Kevin Deisz).


Thanks Benoit. A couple of suggestions would be:

~~~
anonymous_refine
inline_refine
class_refine
refining
refine_class
~~~

Any of these would be fine I think - `anonymous_refine` gets across that it's creating an anonymous module that will be used. `inline_refine` is similar in that sense. `class_refine` may be confusing in that it's not going up to the singleton class and refining. `refining` is inline with Rails' `concerning`, but doesn't particularly convey special meaning. `refine_class` gets across that it's only refining a specific class, which I kind of like the best. 

Would something like `refine_class` be amenable to the core team? 

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

* 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