>
> You can do it a bit shorter.  Note that you don't need the "a=[]" and the
> "self.":
>

Thanks. I have made those changes. Here's a version that finally behaves the 
way I want it to.

class Array

  def cartprod(*b)

    if b.empty? then

      inject {|cp,x| cp.cartprod(x) }

    else
            #assume self an array of arrays
            # 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()