[ruby-core:105816] [Ruby master Feature#12737] Module#defined_refinements
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2021-10-26 19:12:27 UTC
List:
ruby-core #105816
Issue #12737 has been updated by Eregon (Benoit Daloze).
Should the code in the description be `p M.defined_refinements`?
I'm not sure to understand the use case, isn't `using M` doing the same as that `for`?
----------------------------------------
Feature #12737: Module#defined_refinements
https://bugs.ruby-lang.org/issues/12737#change-94337
* Author: shugo (Shugo Maeda)
* Status: Assigned
* Priority: Normal
----------------------------------------
How about to provide Module#defined_refinements, which returns the refinements defined in the receiver as a Hash, as follows:
```
module M
refine String do
$M_String = self
end
refine Integer do
$M_Integer = self
end
end
p Module.defined_refinements #=> {String => $M_String, Integer => $M_Integer}
```
By `Module#defined_refinements`, you can activate refinements globally:
```
for klass, refinement in Module.defined_refinements
klass.prepend(refinement)
end
```
--
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>