Module: Domain::Union::Methods

Defined in:
lib/domain/factory/union.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object

Compares with another domain



33
34
35
36
37
38
39
# File 'lib/domain/factory/union.rb', line 33

def <=>(other)
  mine, yours = sub_domains_of(self), sub_domains_of(other)
  return 0  if self==other || mine==yours
  return -1 if mine.subset?(yours)
  return 1  if mine.superset?(yours)
  super
end

#===(value) ⇒ Object

Checks if ‘value` belongs to this domain



28
29
30
# File 'lib/domain/factory/union.rb', line 28

def ===(value)
  predicate.call(value)
end

#new(first = nil, *args) ⇒ Object

Creates a new instance of this domain



17
18
19
20
21
# File 'lib/domain/factory/union.rb', line 17

def new(first = nil, *args)
  return first if args.empty? && self===first
  return new super(first, *args) if superclass.respond_to?(:new) && (superclass != Object)
  domain_error!(first, *args)
end

#predicateObject



23
24
25
# File 'lib/domain/factory/union.rb', line 23

def predicate
  lambda{|value| sub_domains.any?{|d| d===value } }
end