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=-4.0 required=3.0 tests=AWL,BAYES_00, 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 AB5391F9FC for ; Fri, 26 Mar 2021 16:10:02 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 80297120AAF; Sat, 27 Mar 2021 01:08:56 +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 07DA3120AA9 for ; Sat, 27 Mar 2021 01:08:54 +0900 (JST) Received: by filterdrecv-p3iad2-7d7c446bd4-jqfwg with SMTP id filterdrecv-p3iad2-7d7c446bd4-jqfwg-19-605E0749-D0 2021-03-26 16:09:45.931324587 +0000 UTC m=+250611.556080407 Received: from herokuapp.com (unknown) by ismtpd0150p1mdw1.sendgrid.net (SG) with ESMTP id 1N9861K_TfepAlaaSsbXLg for ; Fri, 26 Mar 2021 16:09:45.817 +0000 (UTC) Date: Fri, 26 Mar 2021 16:09:45 +0000 (UTC) From: tenderlove@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79074 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17749 X-Redmine-Issue-Author: tenderlovemaking X-Redmine-Sender: tenderlovemaking 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?lWh=2FbSnEjJFRTUHRj45oOQBme8zohdTU9K3TxrDAbWICyDMhBC6QTyusZmtoL8?= =?us-ascii?Q?J1Z7IygokNNDbtPxBoFeBUR0ESsptIgSesR+bN+?= =?us-ascii?Q?Vj+HD2zPVH4yU6=2FE6uYDa5VXQmMTAvfhH8PbhFM?= =?us-ascii?Q?ruLxYqtqUj0H4RqMzFNxF2X+myABxrcxgVvmRrn?= =?us-ascii?Q?r4ztlzl09M3kuj5TF7tbd669nYiPHhRaHEiGKM+?= =?us-ascii?Q?r=2FG1GstxdPzSKCxfE=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103039 Subject: [ruby-core:103039] [Ruby master Feature#17749] Const source location without name 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 #17749 has been updated by tenderlovemaking (Aaron Patterson). File 0001-Add-constant-location-information-to-classes.patch added I've renamed it to `source_location`. So it's `A::B.source_location`. ---------------------------------------- Feature #17749: Const source location without name https://bugs.ruby-lang.org/issues/17749#change-91102 * Author: tenderlovemaking (Aaron Patterson) * Status: Open * Priority: Normal ---------------------------------------- Hi, I would like to be able to ask a class or module what its source location is without knowing the name. For example, I want to do this: ```ruby module A class B end end p A::B.const_source_location ``` In other works `A::B.const_source_location` would be equivalent to `A.const_source_location(:B)`. The reason I want to do this is because sometimes it is very difficult to get the name of a constant, and sometimes I don't have access to the constant that "encloses" the class or module. One example: ```ruby ObjectSpace.each_object(Class) do |k| p k.const_source_location end ``` In this case I have class objects, but I can't tell what constant `k` was defined *inside* of. Also I can't trust the "name" method on `k` because sometimes it's not the default method (of course I could work around that, but it's not fun). I've attached a patch that implements the feature, and there is a PR [here](https://github.com/ruby/ruby/pull/4324) Side note: I think I would like "source_location" better than `const_source_location`, but I wanted to just file a feature request so we could talk about the feature in general. ---Files-------------------------------- 0001-Add-constant-location-information-to-classes.patch (5.34 KB) 0001-Add-constant-location-information-to-classes.patch (5.97 KB) -- https://bugs.ruby-lang.org/