unless

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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.124