3 ms·
Ruby has "not", but the precedence rules between "not" and "!" differ
by jjgreen 4y ago
Ruby has "not", but the precedence rules between "not" and "!" differ
- quietbritishjim 4y agoWell I really showed myself up as commenting on a topic that I know nothing about! :-) But that's actually ideal in this context, a really low precedence operator is exactly what you want because you can swap `unless` for `if not` without worring about extra parentheses: send_email if not user_suspended? || user_opt_out?
- greenpeas 4y agoI wouldn't use this. Relying on tricky operator precedence can trip up your readers. It's better to just wrap everything in parentheses. I also use parentheses when mixing && and ||, even though their precedence relationship is (probably) more widely known. I generally avoid `not`, `and`, `or` keywords.