I like fill , but that seems to have been accepted. Here you can return the desired array without mutation b . This was not requested, but it may be useful in some applications:
Array.new(a.size) { |i| b[i] || [0,0] }
You could, of course, put b = in front.
Another way in place:
b.concat [[0,0]]*(a.size-b.size)
Hey, this is fun. Another (assuming elements b are nil ):
a.each_index { |i| b[i] ||= [0,0] } b
source share