jimb
1
Hi,
array = [“one”, “two”, “three”]
array_copy = array
array_copy << “four”
p array
p array_copy
#=>
[“one”, “two”, “three”, “four”]
[“one”, “two”, “three”, “four”]
How can I add an element to “array_copy” and leave “array” unaltered?
Cheers.
jimb
2
Answered my own question.
Array.dup ist the way to go.
jimb
3
array = [“one”, “two”, “three”]
array_copy = array.clone
array_copy << “four”
p array
p array_copy
output:
[“one”, “two”, “three”]
[“one”, “two”, “three”, “four”]