J
Janus Bor
Hi all,
I'm failing at something really basic: copying an array and its
contents, so that I can modify the copy without modifying the original.
Here's an example:
irb(main):006:0> a = [1, 2]
=> [1, 2]
irb(main):007:0> b = a
=> [1, 2]
irb(main):008:0> b.delete(1)
=> 1
irb(main):009:0> b
=> [2]
irb(main):010:0> a
=> [2]
I guess the problem is that arrays are called by name not by value, so
that 'b' copy points to the same adress in memory as 'a'. How can I
create an independent copy of 'a'?
Thanks,
Janus
I'm failing at something really basic: copying an array and its
contents, so that I can modify the copy without modifying the original.
Here's an example:
irb(main):006:0> a = [1, 2]
=> [1, 2]
irb(main):007:0> b = a
=> [1, 2]
irb(main):008:0> b.delete(1)
=> 1
irb(main):009:0> b
=> [2]
irb(main):010:0> a
=> [2]
I guess the problem is that arrays are called by name not by value, so
that 'b' copy points to the same adress in memory as 'a'. How can I
create an independent copy of 'a'?
Thanks,
Janus