Ruby - and, or, and not


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.


aDay = 'Monday'
if aDay == 'Saturday' or aDay == 'Sunday' 
   daytype = 'weekend' 
else #  ww  w  .ja  va 2  s .  c  o  m
   daytype = 'weekday' 

Related Topic