class Array
  
  def power_set

    
    
    
    inject([[]]) do |acc, you|
      ret = []             
      acc.each do |i|      
        ret << i           
        ret << i + [you]   
      end
      ret       
    end

  end

  
  def func_power_set
    inject([[]]) { |ps,item|    
      ps +                      
      ps.map { |e| e + [item] } 
    }
  end
end


require 'set'
class Set
  def powerset 
    inject(Set[Set[]]) do |ps, item| 
      ps.union ps.map {|e| e.union (Set.new [item])}
    end
  end
end

p [1,2,3,4].power_set
p %w(one two three).func_power_set

p Set[1,2,3].powerset