Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/composite_type.rb

Direct Known Subclasses

CompositeType

Defined Under Namespace

Modules: Void Classes: CompositeType, ConjunctiveType, ContainerType, DisjunctiveType, EnumeratedType, NegativeType

Instance Method Summary collapse

Instance Method Details

#&(t) ⇒ Object

Constructs a type which must be A AND B.

Array.of(Positive & Integer)



105
106
107
# File 'lib/composite_type.rb', line 105

def & t
  ConjunctiveType.new_cached(self, t)
end

#of(t) ⇒ Object

Constructs a type of that matches an Enumerable with an element type.

Array.of(String)



44
45
46
# File 'lib/composite_type.rb', line 44

def of t
  ContainerType.new_cached(self, t)
end

#with(*types) ⇒ Object

Constructs a type of Enumerable elements.

String.with(Integer, Float) === [ “foo”, 1, 1.2 ] Hash.of(String.with(Integer))



66
67
68
# File 'lib/composite_type.rb', line 66

def with *types
  EnumeratedType.new_cached(self, *types)
end

#|(t) ⇒ Object

Constructs a type which can be A OR B.

Array.of(String|Integer)



82
83
84
85
86
87
88
89
90
91
# File 'lib/composite_type.rb', line 82

def | t
  case
  when t <= self
    self
  when self <= t
    t
  else
    DisjunctiveType.new_cached(self, t)
  end
end

#~@Object

Constructs a type which must not be A.

Array.of(~ NilClass)



121
122
123
124
125
126
127
128
# File 'lib/composite_type.rb', line 121

def ~@
  case self
  when NegativeType
    self._t.first
  else
    NegativeType.new_cached(self)
  end
end