ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Benoit Daloze <redmine@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:41761] [ruby-trunk - Feature #5781] Query attributes (attribute methods ending in `?` mark)
Date: Wed, 21 Dec 2011 07:44:33 +0900	[thread overview]
Message-ID: <redmine.journal-22895.20111221074432@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-5781.20111220045711@ruby-lang.org


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

  parent reply	other threads:[~2011-12-20 22:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-19 19:57 [ruby-core:41728] [ruby-trunk - Feature #5781][Open] Query attributes (attribute methods ending in `?` mark) Thomas Sawyer
2011-12-20 12:52 ` [ruby-core:41754] [ruby-trunk - Feature #5781][Assigned] " Yui NARUSE
2011-12-20 14:03 ` [ruby-core:41755] [ruby-trunk - Feature #5781] " Yukihiro Matsumoto
2011-12-20 14:47   ` [ruby-core:41756] " Jeremy Bopp
2011-12-20 16:06     ` [ruby-core:41757] " Anurag Priyam
2011-12-20 18:51 ` [ruby-core:41759] " Thomas Sawyer
2011-12-20 18:59 ` [ruby-core:41760] " Thomas Sawyer
2011-12-20 22:44 ` Benoit Daloze [this message]
2011-12-21 19:27 ` [ruby-core:41766] " Joshua Ballanco
2012-10-26 21:31 ` [ruby-core:48362] " ko1 (Koichi Sasada)
2012-12-23 18:43 ` [ruby-core:51098] " trans (Thomas Sawyer)
2012-12-24  2:10 ` [ruby-core:51108] " trans (Thomas Sawyer)
2019-07-13 10:31 ` [ruby-core:93739] [Ruby master Feature#5781] " eregontp
2019-07-15  9:42 ` [ruby-core:93785] " sudo.nice
2020-01-10  6:34 ` [ruby-core:96755] " abaelter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-22895.20111221074432@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).