From: "David A. Black" Date: 2004-10-30T06:13:39+09:00 Subject: Re: Another scrach on head Hi -- On Sat, 30 Oct 2004, Mohammad Khan wrote: > On Fri, 2004-10-29 at 14:38, Jamis Buck wrote: > > > No, I mispoke for the sake of simplification. nil and false _evaluate to > > false_ in a boolean context, and everything else evaluates to _true_ in > > a boolean context. > > > > Thus > > > > puts "here" if false > > puts "there" if nil > > > > would print nothing, whereas > > > > puts "here" if true > > puts "there" if 5 > > puts "everywhere" if 1 && Object.new && :foobar > > > > would print > > > > here > > there > > everywhere > > > > Hope that is clearer. > > > > - Jamis > > In other words > > a = Whatever.new > > puts "a is nil" if a.nil? > puts "a is neither nil, nor false" if a > puts "a is true" if a == true > puts "a is false" if a == false > puts "a is nil again!" if a == nil You could also say puts "a is true" if a puts "a is false" if a.nil? in the Boolean sense of true/false. Ruby provides the constants TRUE and FALSE, for the respective objects; this might be a good way to write your example (and my additions): puts "a is nil" if a.nil? puts "a is neither nil, nor false, nor FALSE" if a puts "a is TRUE" if a == TRUE puts "a is true" if a puts "a is FALSE" if a == FALSE puts "a is false" if not a puts "a is nil again!" if a == nil puts "a is false" if a.nil? Here, I'm using 'true/false' to mean Boolean true/false, and TRUE/FALSE to mean the objects. David -- David A. Black dblack@wobblini.net