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=-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 4187D1F4B4 for ; Fri, 16 Oct 2020 04:19:27 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 435861209AB; Fri, 16 Oct 2020 13:18:48 +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 02CDF120969 for ; Fri, 16 Oct 2020 13:18:45 +0900 (JST) Received: by filterdrecv-p3mdw1-76f79d8b59-d4v8p with SMTP id filterdrecv-p3mdw1-76f79d8b59-d4v8p-19-5F891F49-17 2020-10-16 04:19:21.455924445 +0000 UTC m=+275805.919220189 Received: from herokuapp.com (unknown) by geopod-ismtpd-5-4 (SG) with ESMTP id isQ0SLZ6QuSJ8xXZqX8WzA for ; Fri, 16 Oct 2020 04:19:21.371 +0000 (UTC) Date: Fri, 16 Oct 2020 04:19:21 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76280 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17171 X-Redmine-Issue-Author: marcandre X-Redmine-Sender: jeremyevans0 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?RVE3t853K5scBhbmJHUzZTFFeVC=2FZSUmHZ0Dc+26wcEi2CTgsF1oz0wTSSxGGN?= =?us-ascii?Q?BI6I+bY4MMUcdNz5z+u6OBkeWulR3gwXFvUhcQZ?= =?us-ascii?Q?IPWk0j88GTmfQIC++R66lRUWKVjL2IxnWovF6k9?= =?us-ascii?Q?i0He5uSJmwDf1yEzvVw+wIV3qyT3QuQ4+oWmLph?= =?us-ascii?Q?ZaDw1od6ucKPGoimpUvbK7zCR2HmgrvB5bDBxyy?= =?us-ascii?Q?16n4poWyI=2F6YULfyk=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 100415 Subject: [ruby-core:100415] [Ruby master Feature#17171] Why is the visibility of constants not affected by `private`? 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 #17171 has been updated by jeremyevans0 (Jeremy Evans). marcandre (Marc-Andre Lafortune) wrote in #note-7: > So can we envision issuing a warning for two release cycles? > > Is it feasible to issue a warning for constants that are currently public that would be made private this way? > > Difficult being that call to `private_constant` happens after point of definition: > > ```ruby > class Foo > private > X = 42 > end # => Warn about privacy change > > class Bar > private > X = 42 > private_constant :X > end # => No warning > ``` I think if we do this, we should only warn on access (i.e. `Foo::X`), not definition. This would require internal changes to add a sort of deprecated-public visibility. ---------------------------------------- Feature #17171: Why is the visibility of constants not affected by `private`? https://bugs.ruby-lang.org/issues/17171#change-88030 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal ---------------------------------------- ```ruby class Foo def call_me # ... end private SOME_DATA = %i[...].freeze # is public, why not private? def calc_stuff # is private, ok. # ... end end ```ruby It's probably a naive question, but why shouldn't `SOME_DATA`'s visibility be private? When writing gems, more often than not the constants that I write are not meant for public consumption. I find it redundant (and tiresome) to explicitly write `private_constant :SOME_DATA`. -- https://bugs.ruby-lang.org/