“and” and “or” are like backwards statement modifiers

It occurred to me after reviewing all the feedback to my last post that despite making the connection to statement modifiers, I never directly contrasted the two. And that this might be an even simpler way of explaining the usefulness of and/or in Ruby. I’ve added the following examples to the original post, but in case you missed it:


You can think of and is as a reversed if statement modifier:


Because of the low precedence of and, no extra parentheses are needed here as they would be for &&.


Likewise, or is a reversed unless statement modifier:



Which version to use – if/unless or and/or – depends on your taste and what reads well in a given case. But it’s nice to have the option.