From: Thomas Sawyer Date: 2011-12-21T03:51:30+09:00 Subject: [ruby-core:41759] [ruby-trunk - Feature #5781] Query attributes (attribute methods ending in `?` mark) Issue #5781 has been updated by Thomas Sawyer. @jeremy Been down that road, and it's not as clean as you might expect. You end up needing two methods e.g. `attr_query_reader` and `attr_query_accessor` (`attr_query_writer` would be essentially meaningless). Moreover, adding additional attr methods tends to be one of those "Cambrian explosion" deals --there are vast variations people have devised. Check out Rails for examples. So I don't think it's a good precedence for core Ruby. In fact I've always thought it a bit unfortunate that #attr alone wasn't all we needed. ---------------------------------------- Feature #5781: Query attributes (attribute methods ending in `?` mark) https://bugs.ruby-lang.org/issues/5781 Author: Thomas Sawyer Status: Assigned Priority: Normal Assignee: Yukihiro Matsumoto Category: Target version: 2.0.0 Pretty sure this has come up before, but I'd like to revisit b/c I don't understand why it isn't allowed. Sometimes I define "query" attributes, and in those cases I'd like the reader 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 potentially cleaner code. -- http://redmine.ruby-lang.org