On Tue, Dec 20, 2011 at 8:17 PM, Jeremy Bopp <jeremy / bopp.net> 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 <matz / ruby-lang.org> 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