[ruby-core:113777] [Ruby master Feature#12737] Module#defined_refinements
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2023-06-06 12:00:22 UTC
List:
ruby-core #113777
Issue #12737 has been updated by Eregon (Benoit Daloze).
`Refinement#refined_class` is a bit strange given it can return a module.
How about adding `Refinement#refined_module` as an alias for clarity?
----------------------------------------
Feature #12737: Module#defined_refinements
https://bugs.ruby-lang.org/issues/12737#change-103426
* Author: shugo (Shugo Maeda)
* Status: Closed
* Priority: Normal
* Assignee: shugo (Shugo Maeda)
----------------------------------------
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 M.defined_refinements #=> {String => $M_String, Integer => $M_Integer}
```
By `Module#defined_refinements`, you can activate refinements globally:
```
for klass, refinement in M.defined_refinements
klass.prepend(refinement)
end
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/