Issue #16241 has been updated by zverok (Victor Shepelev).
I believe that is really super-good thing. As I've written elsewhere in this tracker, the most useful case for refinements is "in current module, I want some shortcuts for my code to look cleaner". For example, [here](https://github.com/zverok/drosterize) and [here](https://github.com/zverok/xkcdize) I experimented with representing some graphics algorithm in a most "readable" way, adding really small methods to core (Numeric) and RMagick objects. The point is "here, in this module, I crave for some things to exists in some objects".
So, "inplace refinements" is probably the main kind of refinements the developer could care; while "refinements in a module" could be used, probably, for some "more hygienic" ActiveSupport-alike gems, or some specific blends of Ruby (like `using Geometry` with ton of specific geometry-related services added to numbers and matrices and whatnot).
----------------------------------------
Feature #16241: Shorter syntax for anonymous refinements
https://bugs.ruby-lang.org/issues/16241#change-81909
* Author: palkan (Vladimir Dementyev)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
The original discussion is here https://bugs.ruby-lang.org/issues/14344.
tl;dr
- Refinements are often used in-place with anonymous modules
- Having shorter syntax could lower the barrier of entry for Rubyist wanting to explore this feature
- Previous syntax suggestions were not accepted.
I suggest adding a shorter syntax (technically, API):
```ruby
# before
using(Module.new do
refine Array do
def foo;"bar";end
end
end)
# after
refining Array do
def foo; "bar"; end
end
```
The original idea was to use `using_refined` instead of `refining` but after discussing with Matz we decided that it's too verbose, and `refining` seems better. But is it good enough? Any 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>