From: dementiev.vm@... Date: 2019-01-02T22:41:04+00:00 Subject: [ruby-core:90864] [Ruby trunk Feature#14344] refine at class level Issue #14344 has been updated by palkan (Vladimir Dementyev). I'm also also using refinements a lot and in most cases I use "inlined" refinements, so would be glad to have a shorter syntax (and, actually, have been thinking about it for a long time and was going to propose a feature���and found this ticket). I was thinking about a syntax proposed by Benoit: ```ruby using do refine Array do # ... end end ``` > I believe changing the semantics of refine (to be using+Module.new+refine) based on whether the receiver is a Class or Module is not acceptable. What if we change it only for top-level `refine`? ```ruby # this works refine String do # ... end module Something # this raises an exception refine ... end class AnotherThing # and this raises refine ... end ``` This could be implemented just as syntactic sugar (by defining a `refine` method on vm top). ---------------------------------------- Feature #14344: refine at class level https://bugs.ruby-lang.org/issues/14344#change-76049 * 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: