def deepcopy(input)
begin Marshal.load Marshal.dump input rescue input.map { |i| i.is_a?(Array) ? deepcopy(i) : (begin i.clone rescue i end) } end
end
top=binding;puts <<_EOC.split("\n").map{|i|"#{i}\n=>#{top.eval i}\n\n"}.join
a=[[[11,2],3],4]
a
b=deepcopy(a)
b[0][0][0]=12
b
a
_EOC
def deepcopy(input)
begin Marshal.load Marshal.dump input rescue input.map { |i| i.is_a?(Array) ? deepcopy(i) : (begin i.clone rescue i end) } end
end
top=binding;puts <<_EOC.split("\n").map{|i|"#{i}\n=>#{top.eval i}\n\n"}.join
a=[[[11,2],3],4]
a
b=deepcopy(a)
b[0][0][0]=12
b
a
_EOC