Class: RDL::Type::SingletonType
- Inherits:
-
Type
- Object
- Type
- RDL::Type::SingletonType
show all
- Defined in:
- lib/rdl/types/singleton.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 SingletonType.
20
21
22
23
|
# File 'lib/rdl/types/singleton.rb', line 20
def initialize(val)
@val = val
@nominal = NominalType.new(val.class)
end
|
Instance Attribute Details
#nominal ⇒ Object
Returns the value of attribute nominal.
4
5
6
|
# File 'lib/rdl/types/singleton.rb', line 4
def nominal
@nominal
end
|
#val ⇒ Object
Returns the value of attribute val.
3
4
5
|
# File 'lib/rdl/types/singleton.rb', line 3
def val
@val
end
|
Class Method Details
.__new__ ⇒ Object
10
|
# File 'lib/rdl/types/singleton.rb', line 10
alias :__new__ :new
|
.new(val) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/rdl/types/singleton.rb', line 13
def self.new(val)
t = @@cache[val]
return t if t
t = self.__new__ val
return (@@cache[val] = t)
end
|
Instance Method Details
#<=(other) ⇒ Object
55
56
57
|
# File 'lib/rdl/types/singleton.rb', line 55
def <=(other)
return Type.leq(self, other)
end
|
#==(other) ⇒ Object
Also known as:
eql?
25
26
27
28
29
|
# File 'lib/rdl/types/singleton.rb', line 25
def ==(other)
return false if other.nil?
other = other.canonical
return (other.instance_of? self.class) && (other.val.equal? @val)
end
|
#hash ⇒ Object
40
41
42
|
# File 'lib/rdl/types/singleton.rb', line 40
def hash
return @val.hash
end
|
#instantiate(inst) ⇒ Object
65
66
67
|
# File 'lib/rdl/types/singleton.rb', line 65
def instantiate(inst)
return self
end
|
#match(other) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/rdl/types/singleton.rb', line 33
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
59
60
61
62
63
|
# File 'lib/rdl/types/singleton.rb', line 59
def member?(obj, *args)
t = RDL::Util.rdl_type obj
return t <= self if t
obj.equal?(@val)
end
|
#to_s ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/rdl/types/singleton.rb', line 44
def to_s
if @val.instance_of? Symbol
":#{@val}"
elsif @val.nil?
"nil"
else
@val.to_s
end
end
|