From: "shugo (Shugo Maeda)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:106164] [Ruby master Feature#12737] Module#defined_refinements
Date: Fri, 19 Nov 2021 02:01:21 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-94767.20211119020120.12@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-12737.20160908053811.12@ruby-lang.org
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/
next prev parent reply other threads:[~2021-11-19 2:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-12737.20160908053811.12@ruby-lang.org>
2021-10-26 2:21 ` [ruby-core:105796] [Ruby master Feature#12737] Module#defined_refinements shugo (Shugo Maeda)
2021-10-26 19:12 ` [ruby-core:105816] " Eregon (Benoit Daloze)
2021-11-16 4:43 ` [ruby-core:106076] " shugo (Shugo Maeda)
2021-11-16 12:39 ` [ruby-core:106088] " Eregon (Benoit Daloze)
2021-11-18 5:55 ` [ruby-core:106115] " shugo (Shugo Maeda)
2021-11-18 9:40 ` [ruby-core:106128] " Eregon (Benoit Daloze)
2021-11-19 2:01 ` shugo (Shugo Maeda) [this message]
2021-12-09 7:10 ` [ruby-core:106571] " matz (Yukihiro Matsumoto)
2021-12-10 4:43 ` [ruby-core:106612] " shugo (Shugo Maeda)
2023-06-06 12:00 ` [ruby-core:113777] " Eregon (Benoit Daloze) via ruby-core
2023-06-06 12:37 ` [ruby-core:113778] " shugo (Shugo Maeda) via ruby-core
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-94767.20211119020120.12@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).