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.9 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 9FE771F4B4 for ; Sat, 17 Apr 2021 08:04:47 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E38D1120EC3; Sat, 17 Apr 2021 17:03:44 +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 D94D7120EBF for ; Sat, 17 Apr 2021 17:03:42 +0900 (JST) Received: by filterdrecv-canary-5b5d7d49cb-dgblb with SMTP id filterdrecv-canary-5b5d7d49cb-dgblb-16-607A9699-4E 2021-04-17 08:04:41.861514094 +0000 UTC m=+129072.466593364 Received: from herokuapp.com (unknown) by ismtpd0142p1iad2.sendgrid.net (SG) with ESMTP id 7mZYbbcCTjS2R88cxA_rDw for ; Sat, 17 Apr 2021 08:04:41.840 +0000 (UTC) Date: Sat, 17 Apr 2021 08:04:41 +0000 (UTC) From: fxn@hashref.com Message-ID: References: Mime-Version: 1.0 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-Redmine-MailingListIntegration-Message-Ids: 79543 X-SG-EID: =?us-ascii?Q?nBqvi0=2FX0JUE4l3AKfUjuwxdcsxPcgQmSMOE0TmEhKeDbaIA9kv2V2OECg20pS?= =?us-ascii?Q?nF0iuLm2V5HDgtCityUW4w=2FsEjLz8DhHTPoPJ3s?= =?us-ascii?Q?qG3YGMxh0ObTGdxSIxZMSsZwCJOFuAvFfZMZ+9V?= =?us-ascii?Q?6aE2ojwl3zH9rGQ64psZbxJX+cW0tS9uucrIDNv?= =?us-ascii?Q?3MHZdytErXkUSj+q2rBv1z1AX+Ca=2FIAbvopBnOp?= =?us-ascii?Q?RbmD7HojkoY1D271Q=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103496 Subject: [ruby-core:103496] [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). In my view, the way to implement the use case that matches Ruby is to go downwards. Module has many constants, that is the Ruby model, so instead of ```ruby ObjectSpace.each_object(Class) do |k| k.outer_scope.constants end ``` you'd write ```ruby ObjectSpace.each_object(Module) do |mod| mod.constants.each do |cname| # Do something with cname. end end ``` Alternatively, Recurse starting at `Object` (would miss anonymous modules with constants). ---------------------------------------- Feature #17753: Add Module#namespace https://bugs.ruby-lang.org/issues/17753#change-91592 * 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/