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 E4F121940146 for ; Fri, 22 May 2015 03:48: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 A19EFB5D808 for ; Fri, 22 May 2015 04:05:37 +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 ED23397A826 for ; Fri, 22 May 2015 04:05:37 +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 dEiNuM1MZFmF for ; Fri, 22 May 2015 04:05:37 +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 93A2397A820 for ; Fri, 22 May 2015 04:05:37 +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 45EC695243A for ; Fri, 22 May 2015 04:05:37 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E0F53120482; Fri, 22 May 2015 04:05:34 +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 C53EB12047A for ; Fri, 22 May 2015 04:05:30 +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=Gv4EnHk07QUwH0zickjDK13oBf0=; b=Py/JKW/nPiCbI5D/ld jlWQuPvPBScnPJH+2b55dXCYKHLizWbe/u+CArM/+8vPdT7vaVqIF1WqKWCC8Pz2 ZpmzV+LDGoSmMHUXdUcwIrRyXmyaVCewVqQRJovcqNHzkbRFN6NPy8DJsD9sU3rZ f2RRZMdOzBTsIjCVTayn/XMoU= Received: by filter0274p1mdw1.sendgrid.net with SMTP id filter0274p1mdw1.3545.555E2C7257 2015-05-21 19:05:22.981732641 +0000 UTC Received: from herokuapp.com (ec2-54-205-200-191.compute-1.amazonaws.com [54.205.200.191]) by ismtpd-001 (SG) with ESMTP id 14d77dda07b.920.51ae87 for ; Thu, 21 May 2015 19:05:22 +0000 (UTC) Date: Thu, 21 May 2015 19:05:22 +0000 From: shevegen@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: 43734 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11167 X-Redmine-Issue-Author: shevegen X-Redmine-Sender: shevegen 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS57mdQ8+B12JPxAXoQHtnFO6ldnhMfIIkKZZj vU23LUi45O6A1dhnwurbgY1AjblG0iPVTJ8jgRnSYJRz9d6xGLgaap80gILpBr0I9huA26dUhf67jz 6pLjphA3FUMi01xk1H/cMfEG9dYuMG5ev8cv X-ML-Name: ruby-core X-Mail-Count: 69305 Subject: [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 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 reported by Robert A. Heiler. ---------------------------------------- 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 * 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: 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: 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: attr_reader :foo? Would create both a method foo() and foo?(). People who do not need this, can continue to use: 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/