Array() in Ruby
Dec 27, 2020 - Daniel Viklund
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_ary
, then #to_a
on the passed argument.
Tags: Ruby, Syntax, Coding Style