Class: Array

Inherits:
Object show all
Defined in:
lib/set_theory/union.rb,
lib/set_theory/power_set.rb,
lib/set_theory/difference.rb,
lib/set_theory/intersection.rb,
lib/set_theory/symmetric_difference.rb

Instance Method Summary collapse

Instance Method Details

#difference(ary) ⇒ Object



2
3
4
# File 'lib/set_theory/difference.rb', line 2

def difference(ary)
  self - ary
end

#intersection(ary) ⇒ Object



2
3
4
# File 'lib/set_theory/intersection.rb', line 2

def intersection(ary)
  self & ary
end

#power_setObject



3
4
5
6
7
# File 'lib/set_theory/power_set.rb', line 3

def power_set
  self.inject([[]]) { |set,item|
    set + set.map { |e| e + [item] }
  }
end

#symmetric_difference(ary) ⇒ Object



2
3
4
# File 'lib/set_theory/symmetric_difference.rb', line 2

def symmetric_difference(ary)
  (self | ary) - (self & ary)
end

#union(ary) ⇒ Object



2
3
4
# File 'lib/set_theory/union.rb', line 2

def union(ary)
  self | ary
end