> > You can do it a bit shorter. Note that you don't need the "a=[]" and the > "self.": > DOH! One of my comment lines was misplaced. So here's what I want: class Array def cartprod(*b) if b.empty? then #assume self an array of arrays inject {|cp,x| cp.cartprod(x) } else # use b.flatten or b[0]? # b[0] is probably safer inject([]){|a,x| b[0].inject(a){|a,y| a << [x,y]}} end #if end #cartprod end #Array a=[1,2,3] b=[4,5,6] p a.cartprod(b) p [a,b].cartprod