Module: Cantor
- Defined in:
- lib/cantor.rb,
lib/cantor/null_set.rb,
lib/cantor/absolute_set.rb,
lib/cantor/abstract_set.rb,
lib/cantor/relative_set.rb,
lib/cantor/universal_set.rb,
lib/cantor/relative_complement.rb
Defined Under Namespace
Classes: AbsoluteSet, AbstractSet, RelativeComplement, RelativeSet
Constant Summary
collapse
- NullSet =
Class.new(RelativeSet) do
def initialize
end
def build
self
end
def each
end
def to_a
[]
end
def include?(other)
false
end
def finite?
true
end
def replace(other)
Cantor.build(other)
end
def size
0
end
def empty?
true
end
def map
self
end
def select
self
end
def reject
self
end
def complement
UniversalSet.build
end
def intersection(other)
self
end
def union(other)
Cantor.build(other)
end
def difference(other)
self
end
def symmetric_difference(other)
Cantor.build(other)
end
def ==(other)
eql?(other) or other.empty?
end
def inspect
"NullSet"
end
end.new
- UniversalSet =
Class.new(RelativeComplement) do
def initialize
end
def build
self
end
def include?(object)
true
end
def finite?
false
end
def size
1.0 / 0.0
end
def empty?
false
end
def replace(other)
Cantor.build(other)
end
def complement
NullSet.build
end
def intersection(other)
Cantor.build(other)
end
def union(other)
self
end
def symmetric_difference(other)
Cantor.complement(other)
end
def difference(other)
Cantor.complement(other)
end
def proper_subset?(other)
false
end
def proper_superset?(other)
not other.eql?(self)
end
def ==(other)
eql?(other)
end
def inspect
"UniversalSet"
end
end.new
Class Method Details
42
43
44
45
46
47
48
49
50
|
# File 'lib/cantor.rb', line 42
def absolute(other, universe = other)
if universe == Cantor::UniversalSet
build(other)
elsif universe.eql?(other)
Cantor::AbsoluteSet.build(universe)
else
Cantor::AbsoluteSet.build(universe).intersection(other)
end
end
|
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/cantor.rb', line 15
def build(object)
if object.is_a?(Cantor::AbstractSet)
object
elsif object.is_a?(Enumerable)
Cantor::RelativeSet.build(object)
else
raise TypeError,
"argument must be an AbstractSet or Enumerable"
end
end
|
27
28
29
|
# File 'lib/cantor.rb', line 27
def complement(other)
build(other).complement
end
|
37
38
39
|
# File 'lib/cantor.rb', line 37
def empty
Cantor::NullSet.build
end
|
32
33
34
|
# File 'lib/cantor.rb', line 32
def universal
Cantor::UniversalSet.build
end
|