From: Anurag Priyam Date: 2011-12-21T01:06:03+09:00 Subject: [ruby-core:41757] Re: [ruby-trunk - Feature #5781] Query attributes (attribute methods ending in `?` mark) 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 wrote: > 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. 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 = Foo.new f.bar? #=> nil f.bar = 'meh' f.bar #=> 'meh' f.bar? #=> 'meh' f.baz? #=> 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. -- Anurag Priyam