J
Jamie Hodkinson
Just had something unexpected - is this the correct behaviour?
foo = Array.new(3,Array.new)
foo[0] << 4
foo[1] << 5
foo[0] << 6
p foo
outputs...
[[4, 5, 6], [4, 5, 6], [4, 5, 6]]
I realise what's happening here, and might have expected it if the
first line was
foo = Array.new(3,[])
I'm left with doing this:
foo = (1..3).collect { [] }
which doesn't exactly raise my heartbeat. Any other options?
Cheers
Jamie
foo = Array.new(3,Array.new)
foo[0] << 4
foo[1] << 5
foo[0] << 6
p foo
outputs...
[[4, 5, 6], [4, 5, 6], [4, 5, 6]]
I realise what's happening here, and might have expected it if the
first line was
foo = Array.new(3,[])
I'm left with doing this:
foo = (1..3).collect { [] }
which doesn't exactly raise my heartbeat. Any other options?
Cheers
Jamie