[ruby-core:96755] [Ruby master Feature#5781] Query attributes (attribute methods ending in `?` mark)
[email protected] Fri, 10 Jan 2020 06:34:47 +0000 (UTC)
| Newsgroups | gmane.comp.lang.ruby.core |
|---|---|
| Message-ID | <redmine.journal-83746.20200110063447.4cfb950f124b1a42@ruby-lang.org> |
Issue #5781 has been updated by anders (Anders B=E4lter).
sudo (Sudo Nice) wrote:
> How about implementing it similarly to Crystal?
> =
> attr_accessor? :foo
+1
----------------------------------------
Feature #5781: Query attributes (attribute methods ending in `?` mark)
https://bugs.ruby-lang.org/issues/5781#change-83746
* Author: trans (Thomas Sawyer)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: =
----------------------------------------
Pretty sure this has come up before, but I'd like to revisit b/c I don't un=
derstand why it isn't allowed.
Sometimes I define "query" attributes, and in those cases I'd like the read=
er method to end in a `?` mark. Currently I have to do:
# @attribute
def foo?
@foo
end
or, if I don't mind a shadowing bare method,
attr :foo
alias_method :foo?, :foo
So why not just allow:
attr :foo?
Currently this causes an error. But why? It just seems like a waste of pote=
ntially cleaner code.
-- =
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>