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-Status: No, score=-2.7 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no 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 6A74F1F9FC for ; Sat, 27 Mar 2021 11:33:46 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 52D9B120AF0; Sat, 27 Mar 2021 20:32:40 +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 7DBD6120AEB for ; Sat, 27 Mar 2021 20:32:37 +0900 (JST) Received: by filterdrecv-p3mdw1-85cc49d4fc-s8t9b with SMTP id filterdrecv-p3mdw1-85cc49d4fc-s8t9b-18-605F180D-29 2021-03-27 11:33:33.624298415 +0000 UTC m=+320437.787570806 Received: from herokuapp.com (unknown) by geopod-ismtpd-4-0 (SG) with ESMTP id 69XEuDeTTSSzQemS9UefKQ for ; Sat, 27 Mar 2021 11:33:33.551 +0000 (UTC) Date: Sat, 27 Mar 2021 11:33:33 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79092 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17753 X-Redmine-Issue-Author: tenderlovemaking X-Redmine-Sender: Eregon 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?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr3qTULH9=2FEmB+nXbijFBz?= =?us-ascii?Q?MhHxPgFBxKsagT0iredvwM43sq2VvWinTY=2FnmCb?= =?us-ascii?Q?DIqIGZpqb0WrvyEanhU73TM2NVXRU6BZc9DvBVw?= =?us-ascii?Q?9MhaB4bUSjcwnzsPaEf4PQnuPa0GWlJyvy2RDwR?= =?us-ascii?Q?DUEGOJLx8PmT6kGcrdeeZBjzB1cJLFoZDzhTFXC?= =?us-ascii?Q?FbWvEdBC=2FaIOquIcs=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103057 Subject: [ruby-core:103057] [Ruby master Feature#17753] Add Module#outer_scope 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 Eregon (Benoit Daloze). @sawa I'd say first assignment to a named constant wins, just like for Module#name. I agree with the feature. I'd suggest `Module#namespace` for the name though. For example, I'd say the namespace of `Process::Status` is `Process`. `scope` feels general to me, and there are many other scopes, so I think namespace is a more precise term for it. `namespace` is also the term used in https://github.com/ruby/ruby/blob/master/doc/syntax/modules_and_classes.rdoc#label-Modules ---------------------------------------- Feature #17753: Add Module#outer_scope https://bugs.ruby-lang.org/issues/17753#change-91118 * 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) -- https://bugs.ruby-lang.org/