Ruby - Operator Boolean unless

Introduction

Ruby can perform unless tests, which are the exact opposite of if tests:

Demo

aDay = "Monday"
unless aDay == 'Saturday' or aDay == 'Sunday' 
   daytype = 'weekday' 
else #  ww w.j  a v a2s  .c o  m
   daytype = 'weekend' 
end

unless is an alternative way of expressing "if not."

The following is equivalent to the previous code; both consider Saturday and Sunday to be the weekend and other days to be weekdays:

Demo

aDay = "Monday"
if !(aDay == 'Saturday' or aDay == 'Sunday') 
   daytype = 'weekday' 
else #  ww  w  .  j  a  v a  2  s  .  c  o m
   daytype = 'weekend' 
end

Related Topic