I recently went about cleaning up some of my earlier “syntax mistakes” in a Ruby project of mine. So what do I mean by syntax mistake? It is a term I use to define something that works perfectly fine, but leaves you with that feeling of “shouldn’t there be a nicer way of writing this?”. I think you know the feeling.
When it comes to working with a mix of values or variables, and I want to treat them as an array, I am in the habit of using the
Array(...) method to make sure I am always working with an array, without having to explicitly check for a nil or non-array values. What this method does is that it tries to call first
#to_a on the passed argument.