Project

General

Profile

ActionsLike0

Feature #5781

open

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

Added by trans (Thomas Sawyer) over 13 years ago. Updated about 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 - Feature #12046: Allow attr_reader :foo? to define instance method foo? for accessing @fooRejectedmatz (Yukihiro Matsumoto)Actions
Related to Ruby - Feature #15991: Allow questionmarks in variable namesAssignedmatz (Yukihiro Matsumoto)Actions
Related to Ruby - Feature #19708: Support `attr_reader :foo?`OpenActions

Updated by naruse (Yui NARUSE) over 13 years ago

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)
  • Target version changed from 1.9.4 to 2.0.0

Updated by ko1 (Koichi Sasada) over 12 years ago

  • Target version changed from 2.0.0 to 2.6
#13

Updated by naruse (Yui NARUSE) over 7 years ago

  • Target version deleted (2.6)
#14

Updated by mame (Yusuke Endoh) over 5 years ago

  • Related to Feature #12046: Allow attr_reader :foo? to define instance method foo? for accessing @foo added
#17

Updated by mrkn (Kenta Murata) over 5 years ago

  • Related to Feature #15991: Allow questionmarks in variable names added
#19

Updated by byroot (Jean Boussier) almost 2 years ago

ActionsLike0

Also available in: Atom PDF