[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Newbie Question on Operator Precedence?

7stud --

10/31/2007 1:42:00 AM

Z T wrote:
> What's the reason?


The line:

> puts false or true

is equivalent to:

(puts false) or true

puts returns nil, so that statement is equivalent to:

nil or true

which evaluates to:

false or true

and the result of that is true--but since you didn't save the result in
a variable, it is discarded. Try this:

result = (puts false) or true
p result

--output:--
nil

That result may also be surprising. That's because the statement:

result = (puts false) or true

is equivalent to

(result = (puts false)) or true

puts returns nil, which gets assigned to result, and the statement
becomes:

result or true

which is equivalent to:

nil or true

which is equivalent to:

false or true

which evaluates to true--but since the result isn't stored anywhere, it
is discarded.


> if false or true

That statement is equivalent to:

if (false or true)

which evaluates to:

if true

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