Duplicating an array of strings.
- by Jon
arr = ["red","green","yellow"]
arr2 = arr.clone
arr2[0].replace("blue")
puts arr.inspect
puts arr2.inspect
produces:
["blue", "green", "yellow"]
["blue", "green", "yellow"]
Is there anyway to do a deep copy of an array of strings, other than using Marshal as i understand that is a hack.
I could do:
arr2 = []
arr.each do |e|
arr2 <<…