From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id A3B9E1F4B4 for ; Tue, 13 Apr 2021 09:37:11 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A27441210B9; Tue, 13 Apr 2021 18:36:09 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 376C01210B8 for ; Tue, 13 Apr 2021 18:36:07 +0900 (JST) Received: by filterdrecv-54f669f855-vz7pr with SMTP id filterdrecv-54f669f855-vz7pr-15-60756642-1 2021-04-13 09:37:06.046265094 +0000 UTC m=+45732.122760012 Received: from herokuapp.com (unknown) by ismtpd0153p1mdw1.sendgrid.net (SG) with ESMTP id eZwq7zLUQXWLFqW6tRcd5Q for ; Tue, 13 Apr 2021 09:37:05.922 +0000 (UTC) Date: Tue, 13 Apr 2021 09:37:06 +0000 (UTC) From: fxn@hashref.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79461 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17753 X-Redmine-Issue-Author: tenderlovemaking X-Redmine-Sender: fxn X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?nBqvi0=2FX0JUE4l3AKfUjuwxdcsxPcgQmSMOE0TmEhKcIZtufFKVlgm+TAYUbKd?= =?us-ascii?Q?MeYYdjb5pCRftsA+nwE2c3NFZsJRjHp1EVfOJLh?= =?us-ascii?Q?aA=2F0k8SJbpb7R4Vc7paHm366+nmcfnnpwIYDeSx?= =?us-ascii?Q?UGHo8y=2F+WT9bsyHAgu3AMhM6+mv0WKoJ8h4ZVEm?= =?us-ascii?Q?2E+deWILoIdO8JoWKB+r8=2FtWMTYnzF2pUVw=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103418 Subject: [ruby-core:103418] [Ruby master Feature#17753] Add Module#namespace X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17753 has been updated by fxn (Xavier Noria). BTW, we were discussing yesterday with Aaron that the flag I am raising is about the name `namespace`. What we are defining here is, given a class object is: 1. If the class object is anonymous, return `nil`. 2. Othwerwise, it was assigned to a constant at least once. Let `namespace` be the module object that stored that constant at assignment time if it is an alive object, `nil` if the original object is gone (possible depending on whether the reference is weak or not). We do not have a good name for that. Another thing Aaron is exploring is to define `Module#namespaces`, which would return all modules that store the class object in one of their constants. That is a bit closer to the Ruby model, I believe. ---------------------------------------- Feature #17753: Add Module#namespace https://bugs.ruby-lang.org/issues/17753#change-91509 * Author: tenderlovemaking (Aaron Patterson) * Status: Open * Priority: Normal ---------------------------------------- Given code like this: ```ruby module A module B class C; end class D; end end end ``` We can get from `C` to `B` like `C.outer_scope`, or to `A` like `C.outer_scope.outer_scope`. I want to use this in cases where I don't know the outer scope, but I want to find constants that are "siblings" of a constant. For example, I can do `A::B::C.outer_scope.constants` to find the list of "sibling" constants to `C`. I want to use this feature when walking objects and introspecting. For example: ```ruby ObjectSpace.each_object(Class) do |k| p siblings: k.outer_scope.constants end ``` I've attached a patch that implements this feature, and there is a pull request on GitHub [here](https://github.com/ruby/ruby/pull/4326). ---Files-------------------------------- 0001-Add-Module-outer_scope.patch (5.93 KB) 0001-Add-Module-namespace.patch (5.89 KB) -- https://bugs.ruby-lang.org/