Ruby provides unless and elsif statements. It seems natural to assume that there would be a similar elsunless statement, but there is not. Is there a specific reason for this?
To illustrate, this statement would allow for code like this.
unless broken
# do something
elsunless done
# do something else
end
I'm aware that this code can be rewritten to use if and elsif, but in some cases using unless is clearer.
The logic behind
if/elsestatements usually is:Having one exception:
Adding
unlessin this case can be very useful, as you can switch around your code. What I also love aboutunlessis that you can solely do your standard stuff while checking for an exception. (theelseblock can be left out)Having multiple exceptions:
Here comes the tricky part:
Besides being totally unreadable, I couldn't find a logical meaning to the
elsunlessblock: 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.