Power-Set generating function for Ruby
1 2 class Array 3 # Returns the "power set" for this Array. This means that an array with all 4 # subsets of the array's elements will be returned. 5 def power 6 # the power set line is stolen from http://johncarrino.net/blog/2006/08/11/powerset-in-ruby/ 7 inject([[]]){|c,y|r=[];c.each{|i|r<<i;r<<i+[y]};r} 8 end 9 end