From: Mark Wilson Date: 2003-05-29T13:01:45+09:00 Subject: Set cartesian product The following is a proposed implementation of a cartesian product method for the set class. Comments and suggestions would be welcome. require 'set' require 'tuple' class Set def cproduct(set) set3 = Set.new self.each do |ae| set.each do |be| set3.add(Tuple.new(ae, be)) end end set3 end end tuple.rb is from the Seattle Ruby Brigade's Ruby Audit, which can be downloaded here: http://sourceforge.net/project/showfiles.php?group_id=50485 The Tuple class creates immutable arrays. Methods that would modify the object in place return an error for attempted modification of a frozen object. A deepfreeze method is also added to Enumerable so that the Tuple object can't be unfrozen.