E
E.-R. Bruecklmeier
dear rubyists,
today i noticed a strange bahavior in Array.new while defining multi
dimentional arrays:
p "P1"
foo = Array.new(3,[0,0])
foo.each do |foo1|
p foo1.id
end
p "P2"
foo = Array.new
3.times {foo.push [0,0]}
foo.each do |foo1|
p foo1.id
end
produces:
"P1"
19645868
19645868
19645868
"P2"
19645760
19645748
19645736
Completed(0)
Is it intentional that the new method fills the array with just one
instance of [0,0]? In my sense this is a violation of the PoLS.
Thanks for any hints.
Eric.
today i noticed a strange bahavior in Array.new while defining multi
dimentional arrays:
p "P1"
foo = Array.new(3,[0,0])
foo.each do |foo1|
p foo1.id
end
p "P2"
foo = Array.new
3.times {foo.push [0,0]}
foo.each do |foo1|
p foo1.id
end
produces:
"P1"
19645868
19645868
19645868
"P2"
19645760
19645748
19645736
Completed(0)
Is it intentional that the new method fills the array with just one
instance of [0,0]? In my sense this is a violation of the PoLS.
Thanks for any hints.
Eric.