From: "shugo (Shugo Maeda)" Date: 2021-11-19T02:01:21+00:00 Subject: [ruby-core:106164] [Ruby master Feature#12737] Module#defined_refinements Issue #12737 has been updated by shugo (Shugo Maeda). Eregon (Benoit Daloze) wrote in #note-10: > Module#refinements seems nice and straightforward. I prefer Module#refinements too. > I slightly prefer the array variant. > Since this would be mostly used for debugging, there might not be any need to filter in many cases, i.e., the Refinement#inspect output already shows the refined_class's name, so `p M.refinements` seems typical usage (and the Hash for that case would just be more verbose). The array variant is OK for me if Refinement#refined_class will be introduced. Another use case is testing of Refinements themselves: ``` m = Module.new { refine Integer do .... end refine String do ... end } refinements = m.refinements assert_something ..., refinements[Integer] assert_something ..., refinements[String] ``` However, I may be the only user, so it's not so important. If there are more use cases, Module#refinement_get can be added in the future. ---------------------------------------- Feature #12737: Module#defined_refinements https://bugs.ruby-lang.org/issues/12737#change-94767 * 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 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/ Unsubscribe: