The logic behind if
/ else
statements usually is:
Having one exception:
if exception_a
# do exception stuff
else
# do standard stuff
end
unless exception_a
# do standard stuff
else
# do exception stuff
end
Adding unless
in this case can be very useful, as you can switch around your code. What I also love about unless
is that you can solely do your standard stuff while checking for an exception. (the else
block can be left out)
Having multiple exceptions:
Here comes the tricky part:
if exception_a
# do exception stuff a
elsif exception_b
# do exception stuff b
else
# do standard stuff
end
unless exception_a
# do standard stuff
elsunless exception_b
# do ???
else
# do exception stuff
end
Besides being totally unreadable, I couldn't find a logical meaning to the elsunless
block: What code would you put in there? I still have no idea if that would be some exception stuff or standard code.
Maybe you can explain further what code you would use in such a block.