Using Ruby language enhancements
For the most part, as developers, we should always strive to increase the readability of our code as this will help everyone in the long run. I’ve been in scenarios where I’ve looked back at my code and had trouble understanding what the code was doing. That meant that my code was poorly written. Imagine the toll that this poorly written code may have on the next developer or team that has to use it or, worse, improve it. In contrast, if my code was well written, we wouldn’t have this issue. This is me saying this: please write readable code, and I can’t stress enough the lengths Ruby developers will go to make their code readable over any other enhancement in our code. Ruby comes with some additional tools to achieve this.
The unless sentence
One example of these options is a language enhancement called the unless
sentence. The unless
sentence is a negative if
sentence – that is, it will execute the code only...