From: Thomas Hafner Date: 2007-01-28T03:05:05+09:00 Subject: Re: cartesian product of arrays Peter Szinek wrote/schrieb <45B9E90C.7010106@rubyrailways.com>: > Just a suggestion: it is also possible to reopen Enumerable and put your > code there - in this case, all enumerable types will have this > functionality (e.g. Sets), not only Arrays. Does that follow your suggestion?: #\\\ module Enumerable def cartprod(*args) result = [[]] ([self] + args).each do |b| t, result = result, [] t.each do |a| b.each do |n| result << a + [n] end end end result end end #/// Example: (1..2).cartprod((3..5), (6..8)) Regards Thomas