From: Phillip Gawlowski Date: 2009-12-31T19:53:13+09:00 Subject: Re: Why can't I use "or" here? On 31.12.2009 11:35, Albert Schlef wrote: > Then why can I do this? > > puts (123 or true) > > Are you going to tell me that "123 or true", unlike "123 if true", > *isn't* a statement? I'm afraid I am. It's an evaluation. Boolean evaluation (with "and" / "or" having lower precedence than && / ||). > If "123 or true" isn't a statement, then it's a simple expression. And > then I would be able to do: Take a third option: It's an evaluation. ;) Crash course in Boolean logic: We have two items A and B. Case "AND": return true if, and only if, both "a" *and* "b" are true. Example: irb(main):004:0> a, b = true, true => [true, true] irb(main):005:0> a and b => true irb(main):006:0> b = false => false irb(main):007:0> a and b => false irb(main):008:0> As you see, the evaluation spits back a result: True, if both "a" and "b" are true, false if only "a" or "b" is true. Case "OR": return true if *either* "a" *or* "b" are true Example: irb(main):008:0> a, b = false, false => [false, false] irb(main):009:0> a or b => false irb(main):010:0> a = true => true irb(main):011:0> a or b => true irb(main):012:0> b = false => false irb(main):013:0> a or b => true As you can see, if both "a" and "b" are false, the evaluation returns false ("returns false" meaning "the result is false"). If either "a" *or* "b" are true, the evaluation returns true. Same if both "a" *and* "b" are true. > No, no, no. By `puts (123 if true)` I mean: output the result of `123 if > true`. That's what I said, I was just verbose about it. ;) -- Phillip Gawlowski