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 CB33E1940146 for ; Sat, 23 May 2015 00:11:50 +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 E12E5B5D8C2 for ; Sat, 23 May 2015 00:28:46 +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 CD13497A82C for ; Sat, 23 May 2015 00:28:49 +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 Rf_xj5lOShP6 for ; Sat, 23 May 2015 00:28:49 +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 A091B97A82B for ; Sat, 23 May 2015 00:28:49 +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 8D0AB952439 for ; Sat, 23 May 2015 00:28:45 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 5F80312045A; Sat, 23 May 2015 00:28:44 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id A56B4120439 for ; Sat, 23 May 2015 00:28:40 +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=C/1jRHgU4GNpCCzLqVlE2ac5SHM=; b=UrUMDtgTKTIRc3pk85 kRuSb61nSqhv4Unc0XFI+esv++g0T31n0hzPJX1Yudkz6B6WciDf+Nb3U0CVOrCe zYbzh5Zfoy6fl9GNUoj2c0vGvrnic3y4oedMsANMCnh2u/uZMNLBLjrxUxJJwbEf CfClLxEulfsZHafXE9Lz8TyFM= Received: by filter0343p1mdw1.sendgrid.net with SMTP id filter0343p1mdw1.6993.555F4B1812 2015-05-22 15:28:24.645671732 +0000 UTC Received: from herokuapp.com (ec2-54-163-106-85.compute-1.amazonaws.com [54.163.106.85]) by ismtpd-033 (SG) with ESMTP id 14d7c3d57aa.3953.6196e8 for ; Fri, 22 May 2015 15:28:24 +0000 (UTC) Date: Fri, 22 May 2015 15:28:24 +0000 From: djberg96@gmail.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: 43748 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11167 X-Redmine-Issue-Author: shevegen X-Redmine-Sender: djberg96 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5AnVVwSWRZurfetM4uzraE5LNU8nvl3xHhcM tUgwjS2d3/AHg3UO5Uehv/vliq5MyLTwCtisPIj3tfJ7peqjI86gnDuP449PrDQsG97CKuejEtaAPz SHo8E1urDJuV7ngOfW8hZg/RMoGXLxfZXHLl X-ML-Name: ruby-core X-Mail-Count: 69319 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 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 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): ~~~ 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/