From: "Dan0042 (Daniel DeLorme) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "Dan0042 (Daniel DeLorme)" <noreply@ruby-lang.org>
Subject: [ruby-core:123115] [Ruby Feature#21555] Add support for predicate attribute reader names
Date: Fri, 29 Aug 2025 04:07:02 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-114433.20250829040702.6603@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-21555.20250828225651.6603@ruby-lang.org>
Issue #21555 has been updated by Dan0042 (Daniel DeLorme).
Also related to #5781 #11167 #12046 #15991 #19708
Popular eh?
----------------------------------------
Feature #21555: Add support for predicate attribute reader names
https://bugs.ruby-lang.org/issues/21555#change-114433
* 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/
next prev parent reply other threads:[~2025-08-29 4:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 22:56 [ruby-core:123113] " shan (Shannon Skipper) via ruby-core
2025-08-29 4:07 ` Dan0042 (Daniel DeLorme) via ruby-core [this message]
2025-08-29 7:16 ` [ruby-core:123117] " byroot (Jean Boussier) via ruby-core
2025-08-29 22:57 ` [ruby-core:123130] " shan (Shannon Skipper) via ruby-core
2025-09-11 5:21 ` [ruby-core:123215] " matz (Yukihiro Matsumoto) via ruby-core
2025-09-16 11:50 ` [ruby-core:123260] " Dan0042 (Daniel DeLorme) via ruby-core
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-114433.20250829040702.6603@ruby-lang.org \
--to=ruby-core@ml.ruby-lang.org \
--cc=noreply@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).