Forum: Ruby false

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5a9ba83f28f840c9c2ef79557d3b77b1?d=identicon&s=25 Greg __ (mtnbiker)
on 2007-07-23 03:27
I guess I don't understand the concept of false. I wanted to set flag in
my script manually. At first I

flag = true

and all was well. later I ran a test
if flag

But when I set the flag to false (flag=false), the script doesn't work
correctly. If test before the "if flag" don't evaluate correctly.

Work around is easy enough, just use a string or number for the
variable.

But I think I'm missing something fundamental here. As you may have
already guessed, I don't have a programming background.

Thanks
5a9ba83f28f840c9c2ef79557d3b77b1?d=identicon&s=25 Greg __ (mtnbiker)
on 2007-07-23 03:32
I think something else is going on. Even if I use a string, the script
doesn't work with my equivalent of false. I need to recheck the logic.
0e5dbfebaf7264f443e36754fdc8a4a5?d=identicon&s=25 Michael Bevilacqua-Linn (Guest)
on 2007-07-26 00:45
(Received via mailing list)
False and if are probably as simple as you think they are...

irb(main):001:0> foo = false
=> false
irb(main):002:0> if foo; puts "I'm foo!"; end
=> nil
irb(main):003:0> foo = true
=> true
irb(main):004:0> if foo; puts "I'm foo!"; end
I'm foo!
=> nil
irb(main):005:0>

Chances are you're doing something else wrong...   What does, "The
script
doesn't work correctly" mean?  Is an exception thrown, are you getting
incorrect results?

Code samples are also helpful.

MBL
0de2a19e1f26e4675d7dd363cc0157e9?d=identicon&s=25 Cliff Rowley (Guest)
on 2007-07-26 00:46
(Received via mailing list)
12 34 wrote:
> I think something else is going on. Even if I use a string, the script
> doesn't work with my equivalent of false. I need to recheck the logic.
>
What's your code?
5a9ba83f28f840c9c2ef79557d3b77b1?d=identicon&s=25 Greg __ (mtnbiker)
on 2007-07-26 02:28
Cliff Rowley wrote:
> 12 34 wrote:
>> I think something else is going on. Even if I use a string, the script
>> doesn't work with my equivalent of false. I need to recheck the logic.
>>
> What's your code?

What had happened was that things that were supposed to happen in the
script weren't because my memory card was off line. (The first responded
didn't see my CORRECTION, and he was correct in assuming something else
was wrong). Being new to Ruby I was surprised that the missing card
(which needed to be read) didn't cause an error. After the first posting
I simplified the problem and realized it wasn't the false that was
causing the problem. Later I sorted out what was really going on.

Thanks for responding.
This topic is locked and can not be replied to.