Detect a Dimmension object without .typename
-
my mistake, i was wrong. if left side is false the right side doesn't get evaluated
-
@unknownuser said:
if left side is false the right side doesn't get evaluated
This is my understanding also, but watch because the
and
operator is not the same as&&
. I don't thinkand
will shortcut. -
@jim said:
but watch because the and operator is not the same as &&. I don't think and will shortcut.
I did two more tests for this:
def test3 if always_return_false and always_return_false #... end end def test4 if always_return_true and always_return_true #... end end
Results:
>> test3 call always_return_false nil >> test4 call always_return_true call always_return_true nil
-
Found what the difference between
and
and&&
is:@unknownuser said:
The binary "and" operator will return the logical conjunction of its two operands. It is the same as "&&" but with a lower precedence
-
@thomthom said:
Found what the difference between
and
and&&
is:@unknownuser said:
The binary "and" operator will return the logical conjunction of its two operands. It is the same as "&&" but with a lower precedence
Well that explains something that I've been bitten by a few times..
mask = mask or object.getmask
assigns mask to itself and ors with the results of object.getmask()!!
I end up having to do:
mask = (mask or object.getmask)
What kind of madman would introduce such an operator?
Actually the one that beats all for sheer insanity is ruby.h #define-ing fopen() to be something completely different calling some Ruby thing. What the!, Argggh...
I've got some harsh language for Mr.Ruby when/if I meet him.
Adam
-
I think I've always used
&&
and||
so I've avoided such problems. But I have had unexpected behaviour when I usednot
instead of!
. I usednot
some times simply because I thought it was the same thing - butnot
would read better.Looking at the table of Operator Precedence I can see how it all fits together now. http://www.techotopia.com/index.php/Ruby_Operator_Precedence
-
Sure, it lists them out.
But I see absolutely no compelling reason to have "Logical AND" differing from "Logical composition" wrt precedence.
What is the 'use case' for the 2 forms? Does anyone know?
Adam
-
@adamb said:
What is the 'use case' for the 2 forms? Does anyone know?
maybe to play jokes like this :
myvar = true and false => false myvar => true
-
@adamb said:
I end up having to do:
mask = (mask or object.getmask)
But now you know you can use
mask = mask || object.getmask
It saves typing the parentheses... (FWIW)
-
Saves you typing even more if you type
mask ||= object.getmask
Advertisement