From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on starla X-Spam-Level: X-Spam-Status: No, score=0.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=OaNNU3om; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=Vqre7SK+; dkim-atps=neutral Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 308D61F4EF for ; Fri, 29 Aug 2025 22:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1756508289; bh=x3f2RGgtMfkzUbBYhwrMgEwd+A0iTTs4xUWv7TYu5ZE=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=OaNNU3omdkPz8KRkcMBefvSRVfaDgp8r9NBYme3udyVK8cLg38etfvbgT0+55FpHJ fJYHGCN4cMAE8Y5mYSAPd2/vqHyjO7bkdDwl3tYaprcAO7IQNkbRJQTmgZpS4Dgm3S uG3CiWsBEdumBIuYfZjNxnqEsNm1QCvN92PyKkG0= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id E5F1A48E58 for ; Fri, 29 Aug 2025 22:58:09 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=Vqre7SK+; dkim-atps=neutral Received: from s.wrqvtvvn.outbound-mail.sendgrid.net (s.wrqvtvvn.outbound-mail.sendgrid.net [149.72.120.130]) by nue.mailmanlists.eu (Postfix) with ESMTPS id CBDB648CEF for ; Fri, 29 Aug 2025 22:57:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=date:from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:date:from:subject:to; s=s1; bh=Xg9OZw/0694RbPkz4Z1Jh+3hyErgotkNh0U6rdB2xr0=; b=Vqre7SK+9OMTvb1YwRclAKCB120ydZmeGmJhVe7EqNa6emR6MlxLflOvGPbzMSqLjBgM wdSYEoyvFC7eRgtnWZfZxlE/yHn+bjxrTOvsD5VDRj2tgha73WKgAmoV9PfSyMzKY8cBdF TOuZ8+sp0Prt6cA7bWfUHucxX3okViupF1QtYMIUflDzOJ3xxR1hzs8TVgKtyCqacFuTKh ZINJ3QxZasAQa1hlXGhdURGXkSsnXOIYI96XZlDjTYedEt2+j5rVSdI1u1Lc88YmwWj66H mir/3e/yA5j93NVkcpoJZ+tgKU7m8xcVfqae59SgqrZyCCnCOehSCYpovEN1KucQ== Received: by recvd-7748d67658-2whh5 with SMTP id recvd-7748d67658-2whh5-1-68B23044-10 2025-08-29 22:57:08.498643909 +0000 UTC m=+7452753.428718459 Received: from herokuapp.com (unknown) by geopod-ismtpd-3 (SG) with ESMTP id wAk2zzvTQrej0H4FUurCQQ for ; Fri, 29 Aug 2025 22:57:08.433 +0000 (UTC) Date: Fri, 29 Aug 2025 22:57:08 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 21555 X-Redmine-Issue-Author: shan X-Redmine-Issue-Priority: Normal X-Redmine-Sender: shan 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: 99937 X-SG-EID: =?us-ascii?Q?u001=2E9fGRHcaur0AuvitC=2F1zdJ7W0yF4MIWkxScnW56JP3D1Ru6E8cp4fwU50h?= =?us-ascii?Q?hG=2FIY2Xn1m8ku39wNL1Ycq7qVKPg2at8MlH86pC?= =?us-ascii?Q?QD+axk8pzTV3gFz3n3=2FSnoBn4LRJL7G7db=2F=2FmVh?= =?us-ascii?Q?LXKaFBQkb6E5nt64T9v3ao+ub+bZ427q9lM8vX8?= =?us-ascii?Q?E+7X1na5J3Rt7P8ccYd2u03c4bjWIIdjaAQjXNo?= =?us-ascii?Q?ZeUMKf0p4MGRxbdsNu9fgpa=2FgIp9UO+elpViM1j?= =?us-ascii?Q?PAzKYrLAINHlczBOjpFCDtz5jw=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: J7ZFM4FW7SEQUACOAUT4BQNPTNCA2JA6 X-Message-ID-Hash: J7ZFM4FW7SEQUACOAUT4BQNPTNCA2JA6 X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:123130] [Ruby Feature#21555] Add support for predicate attribute reader names List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "shan (Shannon Skipper) via ruby-core" Cc: "shan (Shannon Skipper)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #21555 has been updated by shan (Shannon Skipper). Dan0042 (Daniel DeLorme) wrote in #note-2: > Also related to #5781 #11167 #12046 #15991 #19708 > Popular eh? Wow! There's already an open ticket for this exact issue even. I apologize for not properly searching before filing. I should have just added a PR link there in retrospect. byroot (Jean Boussier) wrote in #note-3: > > This feature is only supported for attr_reader and attr, not attr_writer or attr_accessor, since setter methods cannot have question marks. > > Using the same logic, `attr_accessor :enabled?` could generate `#enabled?` and `#enabled=` without problem. `attr_writer :enabled?` would be weird though. I was thinking of `attr_writer :enabled?` being weird and dismissed `attr_accessor :enabled?`. I didn't think of the case where you want `attr_reader :enabled?` and `attr_writer :enabled` without `attr_writer :enabled`. I wouldn't mind doing an `attr_reader :enabled?` with `attr_writer :enabled` but agree `attr_accessor :enabled?` makes sense based on the pattern. ---------------------------------------- Feature #21555: Add support for predicate attribute reader names https://bugs.ruby-lang.org/issues/21555#change-114457 * Author: shan (Shannon Skipper) * Status: Open ---------------------------------------- After manually aliasing predicate methods many times, I wanted to propose letting `attr_reader` take predicate method names that correspond to instance variables of the base name without a trailing question mark. https://github.com/ruby/ruby/pull/14391 If the base name method doesn't already exist, a predicate name defines a base name method attribute reader to alias then undefines the base name. For example, this creates an `enabled?` method that reads `@enabled`: ```ruby attr_reader :enabled? ``` This feature is only supported for `attr_reader` and `attr`, not `attr_writer` or `attr_accessor`, since setter methods cannot have question marks. Example: ```ruby class Example attr_reader :valid?, :meaning def initialize @valid = [true, false].sample @meaning = 42 end end Example.new.valid? #=> true ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/