Project

General

Profile

Actions

Feature #5781

open

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

Added by trans (Thomas Sawyer) almost 13 years ago. Updated almost 5 years ago.

Status:
Assigned
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 3 (2 open1 closed)

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 namesAssignedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #19708: Support `attr_reader :foo?`OpenActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0