Ruby - and, or, and not

Introduction

Ruby has two different syntax for testing Boolean (true/false) conditions.

You can use English-language style operators: and, or, and not.

You can use alternative operators && (and), || (or), and ! (not).

The two sets of operators aren't completely interchangeable.

The || operator has a higher precedence than the or operator.

Demo

aDay = 'Monday'
if aDay == 'Saturday' or aDay == 'Sunday' 
   daytype = 'weekend' 
else # from   w w  w  . ja v  a 2 s . c om
   daytype = 'weekday' 
end

Related Topic