Class: RDL::Type::SingletonType
- Inherits:
-
Type
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
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
Returns the value of attribute nominal.
4
5
6
|
# File 'lib/rdl/types/singleton.rb', line 4
def nominal
@nominal
end
|
Returns the value of attribute val.
3
4
5
|
# File 'lib/rdl/types/singleton.rb', line 3
def val
@val
end
|
Class Method Details
10
|
# File 'lib/rdl/types/singleton.rb', line 10
alias :__new__ :new
|
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
|
74
75
76
|
# File 'lib/rdl/types/singleton.rb', line 74
def copy
return self
end
|
40
41
42
|
# File 'lib/rdl/types/singleton.rb', line 40
def hash return @val.hash
end
|
#instantiate(inst) ⇒ Object
66
67
68
|
# File 'lib/rdl/types/singleton.rb', line 66
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
64
|
# File 'lib/rdl/types/singleton.rb', line 59
def member?(obj, *args)
t = RDL::Util.rdl_type obj
return t <= self if t
return true if obj.nil?
obj.equal?(@val)
end
|
#satisfies? {|val| ... } ⇒ Boolean
78
79
80
|
# File 'lib/rdl/types/singleton.rb', line 78
def satisfies?
yield(val)
end
|
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
|
70
71
72
|
# File 'lib/rdl/types/singleton.rb', line 70
def widen
return self
end
|