From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 780771940146 for ; Sat, 23 May 2015 02:28:08 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 815B4B5D962 for ; Sat, 23 May 2015 02:45:07 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id A29FE97A838 for ; Sat, 23 May 2015 02:45:07 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 59dlaRtzRUV0 for ; Sat, 23 May 2015 02:45:07 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 764C997A834 for ; Sat, 23 May 2015 02:45:07 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 4C41C95243A for ; Sat, 23 May 2015 02:45:04 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 70EA4120465; Sat, 23 May 2015 02:45:02 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 01324120432 for ; Sat, 23 May 2015 02:44:58 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=cOuL0sX5B8wDe8sD9yXWo0713bs=; b=rS59aomjd/UTQjKZvp ReWdgxdLdOILFASNxcSoJ11onS4y/gGC/7UCD/YBtZMVfndOUQ8MGlF+Xqqs/JKj 6+FY9sHQ5OEsCZQ9iLwpukukIyV9iwjA0ZPvyLWc2fgAPLbLkWcB5AW7G7aYOeXW a0TiKLp9frJ0SZjSv8vLWDrrA= Received: by filter0308p1mdw1.sendgrid.net with SMTP id filter0308p1mdw1.13602.555F6B1121 2015-05-22 17:44:53.692437639 +0000 UTC Received: from herokuapp.com (ec2-54-235-32-43.compute-1.amazonaws.com [54.235.32.43]) by ismtpd-034 (SG) with ESMTP id 14d7cba4c74.5cb8.4bbb3c for ; Fri, 22 May 2015 17:44:53 +0000 (UTC) Date: Fri, 22 May 2015 17:44:53 +0000 From: billk@cts.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 43749 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11167 X-Redmine-Issue-Author: shevegen X-Redmine-Sender: spatulasnout X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS5nhp7RAyDj7HTojAYkgqZe1Y1qgqmUyFHb/b WlDbhhFtXmYrjZiI2g6jbxOJlwhclkGD63JKGmDnl0JglMcCkZ44AUM+G50j5G5QngGOZ9UZd74FoR DwfHiPx+zdWg4NDjn6upsQAjPZoH9OnSwQ0g X-ML-Name: ruby-core X-Mail-Count: 69320 Subject: [ruby-core:69320] [Ruby trunk - Feature #11167] Allow an attr_ variant for query-methods that end with a question mark '?' character, such as: def foo? returning @foo X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11167 has been updated by B Kelly. Hi Matz, Yukihiro Matsumoto wrote: > Is there any real-world use-case for the proposal? I've wanted this feature for years. :) Here's an example from code I'm working with today: def startup_complete? @startup_complete end I would have preferred: attr_reader :startup_complete? > It seems > > def foo? > @foo > end > > is just fine. Perhaps fine, but clunky. :) In other words, why do we ever use attr_reader (etc.) at all? We use attr_.* because it's preferable to writing a bunch of mini-functions. The reasons are identical for the '?' variant. Regards, Bill ---------------------------------------- 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-52588 * 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): ~~~ I really miss attr_query or whatever you want to name it which would generate a ? method too apeiros: crystal has :P getter? 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/