Detect a Dimmension object without .typename
-
@adamb said:
..and you know for certain Ruby evaluates left to right?

erhh..? no... I just assumed it did. ..it doesn't?
-
I actually thought all scripting/programming languages evaluated left to right. That short-circut logic as a fundamental design.
-
it evaluates left side, then right side and then the operation between.
here is an example:
1==1 && (p "me too";true) => trueso in your example you will not see any speed improvement

-
I didn't understand that example. But I did a test:
def always_return_false puts 'call always_return_false' return false end def always_return_true puts 'call always_return_true' return true end def test1 if always_return_false && always_return_false #... end end def test2 if always_return_true && always_return_true #... end endWhen I run the code:
>> test1 call always_return_false nil >> test2 call always_return_true call always_return_true nilIn the first case when the first check returns
falseit doesn't trigger the second check. I can't understand anything else than.kind_of?would do the same. -
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
andoperator is not the same as&&. I don't thinkandwill 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 endResults:
>> test3 call always_return_false nil >> test4 call always_return_true call always_return_true nil -
Found what the difference between
andand&&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
andand&&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.getmaskassigns 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 usednotinstead of!. I usednotsome times simply because I thought it was the same thing - butnotwould 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.getmaskIt saves typing the parentheses... (FWIW)
-
Saves you typing even more if you type
mask ||= object.getmask
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better ๐
Register LoginAdvertisement