Greetings,

In my program, I fill an array, a, with data and push it onto an array b 
which is initially empty.  At each iteration, all the previous pushed 
values become the same as the last item, so I end up with an array of 
many copies of the last item.  

Can you please help?


Joe.






(rdb:1) c
ACFFX 25.01 15.13 3.25 0 1.45 0 
Breakpoint 1, toplevel at funds:65
funds:66:       a.fill(0)
(rdb:1) p a
["ACFFX", "25.01", "15.13", "3.25", 0, "1.45", 0]
(rdb:1) p b
[["ACFFX", "25.01", "15.13", "3.25", 0, "1.45", 0], ["ACFFX", "25.01", 
"15.13", "3.25", 0, "1.45", 0], ["ACFFX", "25.01", "15.13", "3.25", 0, 
"1.45", 0], ["ACFFX", "25.01", "15.13", "3.25", 0, "1.45", 0]]
(rdb:1) c 
ACINX 28.53 15.63 3.95 7.76 1.05 0 
Breakpoint 1, toplevel at funds:65
funds:65:       b.push(a) 
(rdb:1) p a
["ACINX", "28.53", "15.63", "3.95", "7.76", "1.05", 0]
(rdb:1) p b
[["ACINX", "28.53", "15.63", "3.95", "7.76", "1.05", 0], ["ACINX", 
"28.53", "15.63", "3.95", "7.76", "1.05", 0], ["ACINX", "28.53", 
"15.63", "3.95", "7.76", "1.05", 0], ["ACINX", "28.53", "15.63", "3.95", 
"7.76", "1.05", 0]]
(rdb:1) exit
[Abba:~/ruby] josephal% cat funds
#!/usr/bin/ruby

....

a = Array.new(7, 0)    # a is the line item
b = Array.new          # b is the array of arrays
....

r.each do |i|
    ...
        b.push(a) 
    ...
end