Project

General

Profile

Feature #5781

Query attributes (attribute methods ending in `?` mark)

Added by trans (Thomas Sawyer) over 8 years ago. Updated 6 months ago.

Status:
Assigned
Priority:
Normal
Target version:
-
[ruby-core:41728]

Description

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.


Related issues

Related to Ruby master - Feature #12046: Allow attr_reader :foo? to define instance method foo? for accessing @fooRejectedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #15991: Allow questionmarks in variable namesOpenmatz (Yukihiro Matsumoto)Actions

Also available in: Atom PDF