I would emphasize clarity and generality.
a = [1,2,3]
b = [4,5,6]
c = [7,8,9]
def concat_some(*arr)
arr.reduce([]) { |ar,(a,flag)| flag ? ar.concat(a) : ar }
end
concat_some([a,true], [b,false], [c,true])
#=> [1, 2, 3, 7, 8, 9]
concat_some([a,false], [b,true], [c,false])
#=> [4, 5, 6]
or
def concat_for_indices(*arr, indices)
indices.reduce([]) { |a,i| a.concat(arr[i]) }
end
concat_for_indices(a,b,c,[1,2])
#=> [4, 5, 6, 7, 8, 9]
concat_for_indices(a,b,c,[2])
#=> [7, 8, 9]
concat_for_indices(a,b,c,[])
#=> []
concat_for_indices(a,b,c,[0,1,2])
#=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
or
def concat_except_for_indices(*arr, indices)
((0..arr.size-1).to_a - indices).reduce([]) { |a,i| a.concat(arr[i]) }
end
concat_except_for_indices(a,b,c, [0])
#=> [4, 5, 6, 7, 8, 9]
concat_except_for_indices(a,b,c, [1,2])
#=> [1, 2, 3]
concat_except_for_indices(a,b,c, [])
#=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
concat_except_for_indices(a,b,c, [0,1,2])
#=> []