Remember that in Ruby you seldom have standalone functions. You should probably create a class that has the cartprod method.