Issue #5781 has been updated by Benoit Daloze.


> So why not just allow: attr :foo?

I agree. I know many people wish for that too.

> matz: The other option is removing '?' from instance variables. But as far as I remember no one seriously proposed the idea before, and we haven't got consensus.

What do you mean by removing '?' from instance variables ?
As you said, '?' is already forbidden in instance variable names.

> Thomas Sawyer: It's an open question as to whether #attr and/or #attr_reader should define the plan method too.

I think the plain (bare) method should not be defined (to keep it as clean and simple as possible), and there should not be any conversion (which could lose information).

Also, since attr* :foo? does not conflict with current uses, I think it's fine to use the usual attr* methods.
----------------------------------------
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