Sergio Ruiz wrote:
> let me just give a blip of what i am getting...
> 
>>> a = Array.new(3,[])
> => [[], [], []]

You've made an array containing three copies of a reference to the same 
array instance.

irb(main):001:0> a = Array.new( 3, [] )
=> [[], [], []]
irb(main):002:0> a.each_with_index { |x,i| puts "#{i}: #{x.object_id}" }
0: 8484280
1: 8484280
2: 8484280

I believe you'd want:

a = Array.new( 3 ) { |idx| Array.new() }

That will call the block once for each element, and that block will 
create a new (different) array instance each time it's called.


irb(main):001:0> a = Array.new( 3 ) { |idx| Array.new }
=> [[], [], []]
irb(main):002:0> a[2] << "foo"
=> ["foo"]
irb(main):003:0> a
=> [[], [], ["foo"]]
irb(main):004:0> a.each_with_index { |x,i| puts "#{i}: #{x.object_id}" }
0: 2741440
1: 2741430
2: 2741420

-- 
Posted via http://www.ruby-forum.com/.