arr = [*arr.to_a + [*new_values.to_a]]
Start with:
arr ||= []
And then, depending on whether new_values array or not
arr += new_values # if array arr << new_values # if not arr += [*new_values] # if it could be either
In addition, you can get rid of the test for new_values , taking advantage of the fact that NilClass implements the .to_a => [] method and reduces everything to:
arry ||= [] arr += [*new_values.to_a]
But wait, we can use this trick again and turn everything into a one-liner:
arr = [*arr.to_a + [*new_values.to_a]]
source share