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-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Newbie Question on Operator Precedence?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password