On Nov 15, 2007 5:30 PM, James Britt <james.britt / gmail.com> wrote:
>
> Suraj Kurapati wrote:

> > So, forcing question-mark methods to return only 'true' and 'false'
> > feels far too restrictive and seems to follow a
> > there's-only-one-way-to-do-it philosophy IMHO.
>
> Forcing would be bad, but there is the convention that foo? returns true
> vs. false, not something vs. nil.

There is no such convention in Ruby.

> If a foo? method happens to be returning something other than TrueClass,
> and you start depending on that quirk, you run the risk that a later
> version of that method returns some other non-nil/non-false  object.

There ARE cases in the ruby language where a x? returns something
other than true or false

defined?(a) # => nil
a = 1
defined?(a) # => "local-variable"

By the way, you really meant true instead of TrueClass right?

The real danger is that you start testing 'truth' with expressions
like x == true or x == false.  As long as you don't do that and simply
use the value in conditional expressions like
  if x ...
  x ? ... : ...
and the like you'll be fine.

You rarely need an actual true/false value in Ruby.

For more on this see
http://www.therailsway.com/2007/8/1/dangers-of-cargo-culting


-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/