Whenever you have problems like this one, it's instructive to add some code to print out the object_id of each object of interest at each of several steps in the calculation. Each Ruby object has a unique object_id. The id can be retrieved with the method Object.object_id:
{ "a"=>1 }.object_id
#=> 70225550848400
Let's try it. (I've shortened object_id's to their last three digits to make it easier to see when they change.)
array1 = [["a", "b", "c"], ["a", "b", "c"]]
puts "1a array1.object_id=#{array1.object_id % 1000}"
puts "1b array1.map(&:object_id)=#{array1.map { |e| e.object_id % 1000 } }"
puts
temp1 = ["x", "y", "z"]
puts "2a temp1.object_id=#{temp1.object_id % 1000}"
array1 << temp1
puts "2b array1=#{array1.inspect}"
puts "2c array1.object_id=#{array1.object_id % 1000}"
puts "2d array1.map(&:object_id)=#{array1.map { |e| e.object_id % 1000 } }"
puts
2.times do
temp1[0] = gets.chomp
temp1[1] = gets.chomp
temp1[2] = gets.chomp
puts "3a temp1=#{temp1.inspect}"
puts "3b temp1.object_id=#{temp1.object_id % 1000}"
array1 << temp1
puts "3c array1=#{array1.inspect}"
puts "3d array1.object_id=#{array1.object_id % 1000}"
puts "3e array1.map(&:object_id)=#{array1.map { |e| e.object_id % 1000 } }"
puts
end
prints
1a array1.object_id=900
1b array1.map(&:object_id)=[0, 920]
2a temp1.object_id=480
2b array1=[["a", "b", "c"], ["a", "b", "c"], ["x", "y", "z"]]
2c array1.object_id=900
2d array1.map(&:object_id)=[0, 920, 480]
1
2
3
3a temp1=["1", "2", "3"]
3b temp1.object_id=480
3c array1=[["a", "b", "c"], ["a", "b", "c"], ["1", "2", "3"], ["1", "2", "3"]]
3d array1.object_id=900
3e array1.map(&:object_id)=[0, 920, 480, 480]
4
5
6
3a temp1=["4", "5", "6"]
3b temp1.object_id=480
3c array1=[["a", "b", "c"], ["a", "b", "c"], ["4", "5", "6"], ["4", "5", "6"],
["4", "5", "6"]]
3d array1.object_id=900
3e array1.map(&:object_id)=[0, 920, 480, 480, 480]
You need to study this carefully.
To understand what's going on it may be helpful to think of an array as a container. What you have done is change the contents of a container, but not the container itself, yet array1 is a list of containers.
To make your code work you merely have to change the container as well as the contents. One simple way is to replace:
temp1[0] = gets.chomp
temp1[1] = gets.chomp
temp1[2] = gets.chomp
with
temp1 = [gets.chomp, gets.chomp, gets.chomp]
array1 = [["a", "b", "c"], ["a", "b", "c"]]
puts "1a array1.object_id=#{array1.object_id % 1000}"
puts "1b array1.map(&:object_id)=#{array1.map { |e| e.object_id % 1000 } }"
puts
temp1 = ["x", "y", "z"]
puts "2a temp1.object_id=#{temp1.object_id % 1000}"
array1 << temp1
puts "2b array1=#{array1.inspect}"
puts "2c array1.object_id=#{array1.object_id % 1000}"
puts "2d array1.map(&:object_id)=#{array1.map { |e| e.object_id % 1000 } }"
puts
2.times do
temp1 = [gets.chomp, gets.chomp, gets.chomp]
puts "3a temp1=#{temp1.inspect}"
puts "3b temp1.object_id=#{temp1.object_id % 1000}"
array1 << temp1
puts "3c array1=#{array1.inspect}"
puts "3d array1.object_id=#{array1.object_id % 1000}"
puts "3e array1.map(&:object_id)=#{array1.map { |e| e.object_id % 1000 } }"
puts
end
prints
1a array1.object_id=100
1b array1.map(&:object_id)=[220, 120]
2a temp1.object_id=660
2b array1=[["a", "b", "c"], ["a", "b", "c"], ["x", "y", "z"]]
2c array1.object_id=100
2d array1.map(&:object_id)=[220, 120, 660]
1
2
3
3a temp1=["1", "2", "3"]
3b temp1.object_id=800
3c array1=[["a", "b", "c"], ["a", "b", "c"], ["x", "y", "z"], ["1", "2", "3"]]
3d array1.object_id=100
3e array1.map(&:object_id)=[220, 120, 660, 800]
4
5
6
3a temp1=["4", "5", "6"]
3b temp1.object_id=580
3c array1=[["a", "b", "c"], ["a", "b", "c"], ["x", "y", "z"], ["1", "2", "3"],
["4", "5", "6"]]
3d array1.object_id=100
3e array1.map(&:object_id)=[220, 120, 660, 800, 580]