Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/evoc/array.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#array_difference(other) ⇒ Object
returns the list of items in self that was not in other.
-
#array_intersection ⇒ Object
returns the intersection of a list of lists.
-
#array_union ⇒ Object
returns the union of an array of arraya.
- #include_any?(other) ⇒ Boolean
- #subset?(other) ⇒ Boolean
Class Method Details
.powerset(set) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/evoc/array.rb', line 36 def self.powerset(set) return [set] if set.empty? p = set.pop subset = powerset(set) subset | subset.map { |x| x | [p] } end |
Instance Method Details
#array_difference(other) ⇒ Object
returns the list of items in self that was not in other
32 33 34 |
# File 'lib/evoc/array.rb', line 32 def array_difference(other) self.map {|a| a - other}.array_union end |
#array_intersection ⇒ Object
returns the intersection of a list of lists
22 23 24 25 26 27 28 |
# File 'lib/evoc/array.rb', line 22 def array_intersection if intersection = self.inject(:&) return intersection else return [] end end |
#array_union ⇒ Object
returns the union of an array of arraya
12 13 14 15 16 17 18 |
# File 'lib/evoc/array.rb', line 12 def array_union if union = self.inject(:|) return union else return [] end end |
#include_any?(other) ⇒ Boolean
6 7 8 |
# File 'lib/evoc/array.rb', line 6 def include_any?(other) (self & other).size > 0 end |
#subset?(other) ⇒ Boolean
2 3 4 |
# File 'lib/evoc/array.rb', line 2 def subset?(other) self & other == self end |