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 5B50C17C506C for ; Wed, 21 Dec 2011 00:01:56 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 0DA84EA6A37 for ; Tue, 20 Dec 2011 23:47:20 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 986548FC28 for ; Tue, 20 Dec 2011 23:47:20 +0900 (JST) X-Virus-Scanned: amavisd-new at funfun.nagaokaut.ac.jp Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by localhost (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1lLYQ8MYZBwC for ; Tue, 20 Dec 2011 23:47:20 +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 77BE58FC26 for ; Tue, 20 Dec 2011 23:47:20 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 8A8C095241B for ; Tue, 20 Dec 2011 23:47:16 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id 583D13C21E7B1; Tue, 20 Dec 2011 23:47:15 +0900 (JST) Received: from mail34.mailforbusiness.com (mail34.mailforbusiness.com [66.70.26.100]) by carbon.ruby-lang.org (Postfix) with ESMTP id 4EC553C21ED5D for ; Tue, 20 Dec 2011 23:47:08 +0900 (JST) Received: from mail34.mailforbusiness.com (localhost [127.0.0.1]) by mail34.mailforbusiness.com (Postfix) with ESMTP id 13C9214F5046 for ; Tue, 20 Dec 2011 09:33:04 -0500 (EST) Received: from [10.10.50.127] (67-198-47-100.static.grandenetworks.net [67.198.47.100]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jeremy@bopp.net) by mail34.mailforbusiness.com (Postfix) with ESMTPSA id CF2EF14F4FF1 for ; Tue, 20 Dec 2011 09:33:03 -0500 (EST) Delivered-To: ruby-core@ruby-lang.org Date: Tue, 20 Dec 2011 23:47:08 +0900 Posted: Tue, 20 Dec 2011 08:47:05 -0600 From: Jeremy Bopp Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:41756] Re: [ruby-trunk - Feature #5781] Query attributes (attribute methods ending in `?` mark) To: ruby-core@ruby-lang.org Message-Id: <4EF09FE9.2040607@bopp.net> In-Reply-To: References: X-ML-Name: ruby-core X-Mail-Count: 41756 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111124 Thunderbird/8.0 X-Spam-Checker-Version: SpamAssassin 3.1.7-deb3 (2006-10-05) on carbon.ruby-lang.org X-Spam-Level: X-Spam-Status: No, score=1.0 required=7.0 tests=ARIN,BAYES_20, CONTENT_TYPE_PRESENT,RATWARE_GECKO_BUILD autolearn=disabled version=3.1.7-deb3 X-Enigmail-Version: 1.4a1pre Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: On 12/20/2011 08:03 AM, Yukihiro Matsumoto wrote: > > Issue #5781 has been updated by Yukihiro Matsumoto. > > > It's mostly because semantics. attr :a creates a method corresponding to an instance variable @a. So naively, attr :a? tries to create an instance variables @a? which is not a valid name for a instance variable. > > I don't want to allow instance variable names ending '?', just because ? is for predicates, not for variables. > 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. How about adding an attr_query method that otherwise works identically to attr_reader but creates a method with a '?' on the end of the given name instead? For example, you could use it like this: class Foo attr_query :bar attr_writer :bar end foo = Foo.new foo.bar = true foo.bar? # => true foo.bar = false foo.bar? # => false -Jeremy