Class: Set

Inherits:
Object show all
Defined in:
lib/standard/facets/set.rb

Instance Method Summary collapse

Instance Method Details

#power_setObject

Author:

  • Phrogz



7
8
9
10
11
12
13
14
15
# File 'lib/standard/facets/set.rb', line 7

def power_set
  if empty?
    Set[self]
  else
    any_value = [to_a.first]
    subsubs = (self - any_value).power_set
    subsubs + subsubs.map{ |subset| subset + any_value }
  end
end