If you wanted to assign different variables depending on several different situations, you might be tempted to do so like this:
In these situations, ruby offers a more elegant solution using case statements to do the same thing. It turns out that you can use case statements to declare variables like this:
This is a quick little trick that you could use in this common situation.
Happy coding! :)
If you found this post useful, sign up for my personal mailing list below. Every now and then, I share coding articles that I've found or written that you might find to be useful or interesting.