require 'set'

class Set
  def powerset
    result = Set.new
    for element_map in 0...(1 << self.length) do
      subset = Set.new
      each_with_index do |element, index|
        subset.add(element) if element_map[index] == 1
      end
      result.add(subset)
    end
    return result
  end
end

s = Set[1,2,3]
ps = s.powerset #returns a set of powerset of s
p ps

-- 
Posted via http://www.ruby-forum.com/.