From: djberg96@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:69319] [Ruby trunk - Feature #11167] Allow an attr_ variant for query-methods that end with a question mark '?' character, such as: def foo? returning @foo
Date: Fri, 22 May 2015 15:28:24 +0000 [thread overview]
Message-ID: <redmine.journal-52587.20150522152823.bcb94c8dfa973813@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11167.20150521190518@ruby-lang.org
Issue #11167 has been updated by Daniel Berger.
Abandoned all hope:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/5796
https://www.ruby-forum.com/topic/135195
----------------------------------------
Feature #11167: Allow an attr_ variant for query-methods that end with a question mark '?' character, such as: def foo? returning @foo
https://bugs.ruby-lang.org/issues/11167#change-52587
* Author: Robert A. Heiler
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Hi guys,
Hi nobu :)
Also hi matz if matz reads this, and of course the rest of the core
team and everyone else.
Today on IRC, this mini-discussion happened (I show a snippet):
~~~
<apeiros> I really miss attr_query or whatever you want to name it
<apeiros> which would generate a ? method too
<jhass> apeiros: crystal has :P getter?
<apeiros> nice
~~~
Ok, so the language crystal has something ruby does not have.
We can't let those newcomers get away with making ruby look old
now can we!
I use ruby not crystal but I very often use methods that end
with a '?' query mark in ruby. It helps me in simple if clauses
such as:
~~~ruby
if hash.has_key?
if hash.key?
if cat.is_hungry?
~~~
(In the latter, it might be a cat of class `Cat` instance, with
an instance variable called `@is_hungry`, and when the cat is
fed with food, it is not hungry logically.)
We can generate these `@ivars` through `attr_`* right now as is
already, such as:
~~~ruby
attr_reader :foo
def foo; @foo; end
attr_writer :foo
def foo=(i); @foo = i; end
attr_accessor :foo
^^^ Combines the above two methods into one.
~~~
But we have no way to designate methods that end via '?'.
I do not know which API call would be nice. apeiros on
IRC suggested `attr_query`
I am fine with that. (The name is secondary for me, I
would like to have this feature available - what name
it would then have is not the main issue for me.)
apeiros then also suggested this syntax:
All `attr_`* that would end with a `?` token, would be a
combination of `attr_reader` and also a variant of the
above that has a '?' token, so for example:
~~~ruby
attr_reader :foo?
~~~
Would create both a method `foo()` and `foo?()`.
People who do not need this, can continue to use:
~~~ruby
attr_reader :foo
~~~
just fine.
So perhaps this suggestion is even better than
a new method (such as through `attr_query()`)
(I also have added one more line from apeiros,
not sure if I understood it, but I think the
above explanation should suffice - here is the
other suggestion he did:)
~~~
apeiros> e.g. attr_reader :foo? -> foo? // attr_accessor :foo? -> foo= + foo? // all with @foo of course. and foo? returning true/false.
~~~
Ok, that's it.
Thanks for reading!
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2015-05-22 15:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-11167.20150521190518@ruby-lang.org>
2015-05-21 19:05 ` [ruby-core:69305] [Ruby trunk - Feature #11167] [Open] Allow an attr_ variant for query-methods that end with a question mark '?' character, such as: def foo? returning @foo shevegen
2015-05-21 23:03 ` [ruby-core:69308] [Ruby trunk - Feature #11167] " nobu
2015-05-22 12:43 ` [ruby-core:69318] " matz
2015-05-22 15:28 ` djberg96 [this message]
2015-05-22 17:44 ` [ruby-core:69320] " billk
2015-05-23 11:28 ` [ruby-core:69326] " duerst
2020-01-10 6:33 ` [ruby-core:96754] [Ruby master Feature#11167] " 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-52587.20150522152823.bcb94c8dfa973813@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).