I want to create a fixed size array with a default number of elements already filled from another array, so lets say that I have this method:
def fixed_array(size, other)
array = Array.new(size)
other.each_with_index { |x, i| array[i] = x }
array
end
So then I can use the method like:
fixed_array(5, [1, 2, 3])
And I will get
[1, 2, 3, nil, nil]
Is there an easier way to do that in ruby? Like expanding the current size of the array I already have with nil objects?