From: Steven Haryanto Date: 2001-06-16T17:58:00+09:00 Subject: [ruby-talk:16532] Re: why only nil and false are regarded as false? On 16/06/2001 11:26, Dave Thomas wrote: >Steven Haryanto writes: > > > I would appreciate some explanation on why Ruby behaves like > > this > >I suspect because the alternatives in other languages were error >prone. I know I've been bitten by loops that terminated prematurely in >Perl. > >Do you have some examples where you'd like other values to be false? So far my mind has been fitted with these idioms: # if string s is empty if (not s) ... # if number is zero if (not n) ... # if there are no elements in array a if (not a) ... I believe this idiom goes as far back as C and perhaps even further. However, in Ruby they will all be wrong. What are the preferred way to do this? Regards Steve