Ruby also can also perform unless
tests, which are the exact opposite of if
tests:
unless.rb
unless aDay == 'Saturday' or aDay == 'Sunday' daytype = 'weekday' else daytype = 'weekend' end
Think of unless
as being 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:
if !(aDay == 'Saturday' or aDay == 'Sunday') daytype = 'weekday' else daytype = 'weekend' end