7stud -- wrote:
>
> Experienced programmers in other languages often get tripped up by ruby 
> because they expect things like empty strings(""), empty arrays([]) or 
> empty hashes({}) to evaluate to false.  But because none of those things 
> is specifically false or nil, they evaluate to true.  It's that simple.
>

Oh, yeah.  I forgot about the big one: 0 (zero).  In languages like C 
and C++, 0 evaluates to false.  But in ruby 0 is not the value false or 
nil, so 0 evaluates to true.  That one trips up a lot of programmers.

So when your method returns a value and you want to know if that value 
will be considered true or false in an if statement, here is your check 
list:


1) Is the value actually the value false?
2) Is the value nil?

If you answered 'yes' to 1 or 2, then value will evaluate to false in an 
if statement.

3) Is the value something other than false or nil?

If yes, then the value will evaluate to true in an if statement.




-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to