Class: RDL::Type::NominalType
- Inherits:
-
Type
- Object
- Type
- RDL::Type::NominalType
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
#name ⇒ Object
3
4
5
|
# File 'lib/rdl/types/nominal.rb', line 3
def name
@name
end
|
Class Method Details
.__new__ ⇒ Object
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
60
61
62
|
# File 'lib/rdl/types/nominal.rb', line 60
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
|
#hash ⇒ Object
38
39
40
|
# File 'lib/rdl/types/nominal.rb', line 38
def hash return @name.hash
end
|
#instantiate(inst) ⇒ Object
71
72
73
|
# File 'lib/rdl/types/nominal.rb', line 71
def instantiate(inst)
return self
end
|
#klass ⇒ Object
55
56
57
58
|
# File 'lib/rdl/types/nominal.rb', line 55
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
64
65
66
67
68
69
|
# File 'lib/rdl/types/nominal.rb', line 64
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
|
#to_s ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/rdl/types/nominal.rb', line 42
def to_s
if @name.start_with? '#<Class:'
if @name['('] n = @name.split('(')[0] + '>'
else
n = @name
end
return RDL::Util.add_singleton_marker(n[8..-2])
else
return @name
end
end
|