From: walter a kehowski Date: 2005-08-08T07:11:08+09:00 Subject: Re: cartesian product Hello, Here's what I have so far, combining the previous suggestions of Robert Klemme and Martin DeMello: class Array def cartprod(a,b) a.each {|ae| b.each {|be| if block_given? yield ae,be else (c ||= []) << ae,be end end end #Array However, c=cartprod([1,2,3],[4,5,6]) c.each { |ce| print ce,"\n" } gives the following syntax error: cartprod.rb:24: syntax error (c ||= []) << ae,be ^ cartprod.rb:26: syntax error cartprod.rb:132: syntax error and I would like to take the cartesian product of an arbitrary number of sets in the most elegant way.