Lets say I have the following line of code: return nil unless app && ip || device
Without parenthesis, how will Ruby interpret the precedence? (app && ip) || device
? or app && (ip || device)
?
Or some other way?
Thanks!
Lets say I have the following line of code: return nil unless app && ip || device
Without parenthesis, how will Ruby interpret the precedence? (app && ip) || device
? or app && (ip || device)
?
Or some other way?
Thanks!
It's simple - since &&
has higher precedence than ||
, it will be interpreted as
(app && ip) || device
I'd recommend to always add the parentheses for readability purposes, though.