From: "Earlopain (Earlopain _) via ruby-core" Date: 2026-07-13T18:41:11+00:00 Subject: [ruby-core:126073] [Ruby Feature#19708] Support `attr_reader :foo?` Issue #19708 has been updated by Earlopain (Earlopain _). Status changed from Open to Closed Sadly https://bugs.ruby-lang.org/issues/21555#note-10 > I still ask you to define def valid? = @valid manually. It is not much worse than attr_reader :valid?. ---------------------------------------- Feature #19708: Support `attr_reader :foo?` https://bugs.ruby-lang.org/issues/19708#change-118073 * Author: AMomchilov (Alexander Momchilov) * Status: Closed ---------------------------------------- Creating reader methods with `attr_reader` is preferable over defining them by hand, not only because it's more convenient, but also because it hits a fast path in MRI (see `VM_METHOD_TYPE_IVAR`). Since local and instance variables can't end with `?`, you can't use `attr_reader` to define predicate-style methods for boolean values, like: ```ruby class Person attr_reader :name, :age, :active? # invalid attribute name `active?' (NameError) def initialize @name = "Bob" @age = 30 @active = true end end ``` It would be nice if `attr_reader` (and friends) could behave like: ```ruby def active? = @active ``` (`attr_writer` and `attr_accessor` couldn't do the same, since `def active?=(new_value)` isn't valid, so they'd probably stick with `def active=(new_value)`) -- 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/