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 6AAC117C506C for ; Wed, 21 Dec 2011 01:20:50 +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 9185FEA6A59 for ; Wed, 21 Dec 2011 01:06:12 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id AE4AC8FC21 for ; Wed, 21 Dec 2011 01:06:14 +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 GxYKTJgw46Yx for ; Wed, 21 Dec 2011 01:06:14 +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 8D8338FC1F for ; Wed, 21 Dec 2011 01:06:14 +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 6765295241E for ; Wed, 21 Dec 2011 01:06:10 +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 ABC2D3C21EBBD; Wed, 21 Dec 2011 01:06:08 +0900 (JST) Received: from mail-yx0-f178.google.com (mail-yx0-f178.google.com [209.85.213.178]) by carbon.ruby-lang.org (Postfix) with ESMTP id 6C6783C21EBA8 for ; Wed, 21 Dec 2011 01:06:03 +0900 (JST) Received: by yenm5 with SMTP id m5so4352272yen.37 for ; Tue, 20 Dec 2011 08:06:02 -0800 (PST) Received: by 10.236.173.233 with SMTP id v69mr4725419yhl.46.1324397162176; Tue, 20 Dec 2011 08:06:02 -0800 (PST) Received: by 10.146.236.10 with HTTP; Tue, 20 Dec 2011 08:05:31 -0800 (PST) Delivered-To: ruby-core@ruby-lang.org Date: Wed, 21 Dec 2011 01:06:03 +0900 Posted: Tue, 20 Dec 2011 21:35:31 +0530 From: Anurag Priyam Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:41757] Re: [ruby-trunk - Feature #5781] Query attributes (attribute methods ending in `?` mark) To: ruby-core@ruby-lang.org Message-Id: In-Reply-To: <4EF09FE9.2040607@bopp.net> References: <4EF09FE9.2040607@bopp.net> X-ML-Name: ruby-core X-Mail-Count: 41757 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= 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=-3.4 required=7.0 tests=ARIN,BAYES_05, CONTENT_TYPE_PRESENT,MIMEQENC,QENCPTR1,QENCPTR2 autolearn=disabled version=3.1.7-deb3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=kpdVQbBJ8xmzr4XkoVi7xv+D0UCa2fnbxysy4OKo1Ns=; b=XLYjl3YFAXsx1kEsaiakHLmm6ZviSWO9FxGNlefn1lSM6HH1NhicinGg107W486lPK BdOSyZlu909hVhCpyZ0v4/B18bG6wbgJyrHfgm1nYqOXCuR62ZSA6atE2HEOropxHNto v2u0aIOd2u5/e4WntXMJ8B8u5Au5HT85GaplQ= Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 Tue, Dec 20, 2011 at 8:17 PM, Jeremy Bopp wrote: > 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? I would suggest the name `predicate` instead. class Foo attr :bar predicate :bar end Alternatively, On Tue, Dec 20, 2011 at 7:33 PM, Yukihiro Matsumoto wr= ote: > The other option is removing '?' from instance variables. =A0But as far a= s I remember no one seriously proposed the idea before, and we haven't got = consensus. Use `attr`, but if the variable name passed to `attr` contains a '?' define a predicate corresponding to it too. class Foo attr :bar? attr :baz end f =3D Foo.new f.bar? #=3D> nil f.bar =3D 'meh' f.bar #=3D> 'meh' f.bar? #=3D> 'meh' f.baz? #=3D> NoMethodError The predicate could be made to strictly return `true` or `false` instead of simply behaving like an attribute reader. The former is perhaps easier to implement, but I would like to use the latter approach in my code. --=20 Anurag Priyam