Ruby idiom to ensure variable is Array
Stop doing this:
arry = input || [] # handle input == nil
arry = [input] unless arry.kind_of?(Array) # handle single value object
arry.each do |item|
#process item
end
In Ruby, you should use Kernel#Array to convert the variable into an array object:
Array(input).each do |item|
# process item
end
# Array(nil) # => []
# Array("foo") # => ["foo"]
# Array([1,2,3]) # => [1,2,3]
More usage examples written in minitest.