From: Jeremy Bopp Date: 2011-12-20T23:47:08+09:00 Subject: [ruby-core:41756] Re: [ruby-trunk - Feature #5781] Query attributes (attribute methods ending in `?` mark) 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