Module: Combinatorics::PowerSet::Mixin
Overview
Instance Method Summary collapse
-
#powerset {|subset| ... } ⇒ Enumerator
(also: #power_set)
Calculates the power-set of an Enumerable object.
Instance Method Details
#powerset {|subset| ... } ⇒ Enumerator Also known as: power_set
Calculates the power-set of an Enumerable object.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/combinatorics/power_set/mixin.rb', line 33 def powerset return enum_for(:powerset) unless block_given? elements = self.to_a elements.uniq! 0.upto(elements.length) do |k| elements.combination(k) do |subset| yield Set.new(subset) end end end |