Do you want this?
#!/usr/bin/ruby -w
a, b, c, d = [1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7], [10, 8, 7, 8]
ba, oth, bb = [b, c, d], a.dup, [a.dup]
ba.each { |i| i.-(oth).tap { |v| bb.push(v) }.each { |i| oth.push(i) } }
p bb
Output
[[1, 2, 3, 4], [5], [6], [7]]
Or the Efficient Way
a = Array.new(10, &:itself)
ba = [Array.new(15, &:next), Array.new(20, &:next) ]
oth, bb = a.dup, [a.dup]
ba.each { |i| bb.push(i.-(oth).tap { |v| oth.concat(v) }) }
p bb
This code is similar, but you see, it has more arrays. On the other hand, pushing each element is way more expensive (slower, resource hogging) than concating all the elements altogether. The output will be
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]
With 100 Arrays?
a = [1,2,3,4]
ba = 100.times.map { rand(2..10).times.map { rand(1..0xfffffffff) } }
oth, bb = a.dup, [a.dup]
ba.each { |i| bb.push(i.-(oth).tap { |v| oth.concat(v) }) }
p bb
Output
Well, you know it will mess up everything here!
I apologise for the variable names. I don’t have sweet names for them
Hope this answers your question!