There are two ways by which we can copy one Array to the other.
Let us look at the first way using the Array() method.
x = ["Mohan", "Kriti", "Salim"] y = Array(x) puts "The Copied Array is : #{y}"
So, in the above code we have created a Array and initialised to the variable x.
x = ["Mohan", "Kriti", "Salim"]
Below is how the values are positioned in the Array,
Then we have used the Array() method to take the Array x as parameter and create a new Array that would be the exact copy of x.
Then assign it to y.
y = Array(x)
And we get the below output,
The Copied Array is : ['Mohan', 'Kriti', 'Salim']
Now, let us look at the second way of copying a Array using =.
x = ["Mohan", "Kriti", "Salim"] y = x puts "The Copied Array is : #{y}"
So, in the above code we have created a Array and initialised to the variable x.
x = ["Mohan", "Kriti", "Salim"]
Below is how the values are positioned in the Array,
Then we have used the assignment operator, = that would create an exact copy of x. And assign it to y.
y = x
And we get the below output,
The Copied Array is ['Mohan', 'Kriti', 'Salim']