Module: Stupidedi::Sets
- Defined in:
- lib/stupidedi/sets.rb,
lib/stupidedi/sets/null_set.rb,
lib/stupidedi/sets/absolute_set.rb,
lib/stupidedi/sets/abstract_set.rb,
lib/stupidedi/sets/relative_set.rb,
lib/stupidedi/sets/universal_set.rb,
lib/stupidedi/sets/relative_complement.rb
Defined Under Namespace
Classes: AbsoluteSet, AbstractSet, RelativeComplement, RelativeSet
Constant Summary collapse
- NullSet =
Class.new(RelativeSet) do def initialize end # @return [NullSet] def build self end # Yields each element in the set to the implicit block argument. Since # there are no elements, the block is never executed # # @return [void] def each end # Returns an {Array} containing each element in this set. Since there are # no elements, the {Array} is empty # # @return [Array] def to_a [] end # @return false def include?(other) false end # @return true def finite? true end # @return [Set] other def replace(other) Sets.build(other) end # @return 0 def size 0 end # @return true def empty? true end # @group Set Operations ######################################################################### # @return self def map self end # @return self def select self end # @return self def reject self end # @return UniversalSet def complement # ¬∅ = U UniversalSet.build end # @return self def intersection(other) # ∅ ∩ A = ∅ self end # @return [Set] other def union(other) # ∅ ∪ A = A Sets.build(other) end # @return self def difference(other) # ∅ ∖ A = A self end # @return [Set] other def symmetric_difference(other) # ∅ ⊖ A = A Sets.build(other) end # @group Set Ordering ######################################################################### def ==(other) eql?(other) or other.empty? end # @group Pretty Printing ######################################################################### # @return [String] def inspect "NullSet" end # @endgroup ######################################################################### end.new
- UniversalSet =
Class.new(RelativeComplement) do def initialize end # @return [UniversalSet] def build self end # @return true def include?(object) true end # @return false def finite? false end # @return Infinity def size 1.0 / 0.0 end # @return false def empty? false end # @return [AbstractSet] def replace(other) Sets.build(other) end # @group Set Operations ######################################################################### # @return NullSet def complement # ¬U = ∅ NullSet.build end # @return [AbstractSet] def intersection(other) # U & A = A Sets.build(other) end # @return [AbstractSet] def union(other) # U ∪ A = U self end # @return [AbstractSet] def symmetric_difference(other) # U ⊖ A = (U ∖ A) ∪ (A ∖ U) = (¬A) ∪ (∅) = ¬A Sets.complement(other) end # @return [AbstractSet] def difference(other) # U ∖ A = ¬A Sets.complement(other) end # @group Set Ordering ######################################################################### # @return [Boolean] def proper_subset?(other) false end # @return [Boolean] def proper_superset?(other) not other.eql?(self) end # @return [Boolean] def ==(other) eql?(other) end # @group Pretty Printing ######################################################################### # @return [String] def inspect "UniversalSet" end # @endgroup ######################################################################### end.new
Constructors collapse
- .absolute(other, universe = other) ⇒ Sets::AbsoluteSet
- .build(object) ⇒ Sets::AbstractSet
- .complement(other) ⇒ Sets::AbstractSet
- .empty ⇒ Sets::NullSet
- .universal ⇒ Sets::UniversalSet
Class Method Details
.absolute(other, universe = other) ⇒ Sets::AbsoluteSet
44 45 46 47 48 49 50 |
# File 'lib/stupidedi/sets.rb', line 44 def absolute(other, universe = other) if universe.eql?(other) Sets::AbsoluteSet.build(universe) else Sets::AbsoluteSet.build(universe).intersection(other) end end |
.build(object) ⇒ Sets::AbstractSet
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/stupidedi/sets.rb', line 17 def build(object) if object.is_a?(Sets::AbstractSet) object elsif object.is_a?(Enumerable) Sets::RelativeSet.build(object) else raise TypeError, "argument must be an AbstractSet or Enumerable" end end |
.complement(other) ⇒ Sets::AbstractSet
29 30 31 |
# File 'lib/stupidedi/sets.rb', line 29 def complement(other) build(other).complement end |
.empty ⇒ Sets::NullSet
39 40 41 |
# File 'lib/stupidedi/sets.rb', line 39 def empty Sets::NullSet.build end |
.universal ⇒ Sets::UniversalSet
34 35 36 |
# File 'lib/stupidedi/sets.rb', line 34 def universal Sets::UniversalSet.build end |