Class: RDL::Type::NominalType
- Inherits:
-
Type
show all
- Defined in:
- lib/rdl/types/nominal.rb
Constant Summary
collapse
- @@cache =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Type
#canonical, leq, #nil_type?, #optional?, #to_contract, #vararg?
Constructor Details
Returns a new instance of NominalType.
19
20
21
|
# File 'lib/rdl/types/nominal.rb', line 19
def initialize(name)
@name = name
end
|
Instance Attribute Details
3
4
5
|
# File 'lib/rdl/types/nominal.rb', line 3
def name
@name
end
|
Class Method Details
8
|
# File 'lib/rdl/types/nominal.rb', line 8
alias :__new__ :new
|
.new(name) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/rdl/types/nominal.rb', line 11
def self.new(name)
name = name.to_s
t = @@cache[name]
return t if t
t = self.__new__ name
return (@@cache[name] = t)
end
|
Instance Method Details
#<=(other) ⇒ Object
51
52
53
|
# File 'lib/rdl/types/nominal.rb', line 51
def <=(other)
return Type.leq(self, other)
end
|
#==(other) ⇒ Object
Also known as:
eql?
23
24
25
26
27
|
# File 'lib/rdl/types/nominal.rb', line 23
def ==(other)
return false if other.nil?
other = other.canonical
return (other.instance_of? self.class) && (other.name == @name)
end
|
38
39
40
|
# File 'lib/rdl/types/nominal.rb', line 38
def hash
return @name.hash
end
|
#instantiate(inst) ⇒ Object
62
63
64
|
# File 'lib/rdl/types/nominal.rb', line 62
def instantiate(inst)
return self
end
|
46
47
48
49
|
# File 'lib/rdl/types/nominal.rb', line 46
def klass
@klass = RDL::Util.to_class(name) unless defined? @klass
return @klass
end
|
#match(other) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/rdl/types/nominal.rb', line 31
def match(other)
other = other.canonical
other = other.type if other.instance_of? AnnotatedArgType
return true if other.instance_of? WildQuery
return self == other
end
|
#member?(obj, *args) ⇒ Boolean
55
56
57
58
59
60
|
# File 'lib/rdl/types/nominal.rb', line 55
def member?(obj, *args)
t = RDL::Util.rdl_type obj
return t <= self if t
return true if obj.nil?
return obj.is_a? klass
end
|
42
43
44
|
# File 'lib/rdl/types/nominal.rb', line 42
def to_s
return @name
end
|