I tried to solve a kata today that took me through a loop through one portion of the exercise. The problem I experienced can be simplified to the following nuance:
node = [1]
root_node = node
node << 2
p node #[1,2]
p root_node #[1,2]
node = 1
root_node = node
new_node = 3
node = new_node
p node #3
p root_node #1
Why is it that node
and root_node
both change when I modify the array assigned to one variable but assigning values to a variable doesn't modify the other?
I would have expected node = [1,2]
and root_node = [1]
.
Could someone shed light onto this or direct me towards documentation regarding this. I don't think I ever noticed that that was the case. Thank you.