Class: Array
- 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
- #difference(ary) ⇒ Object
- #intersection(ary) ⇒ Object
-
#power_set ⇒ Object
Taken from rosettacode.org/wiki/Power_Set#Ruby.
- #symmetric_difference(ary) ⇒ Object
- #union(ary) ⇒ Object
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_set ⇒ Object
Taken from rosettacode.org/wiki/Power_Set#Ruby
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 |