Class: RDL::Type::VarargType
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
Constructor Details
19
20
21
22
23
24
25
|
# File 'lib/rdl/types/vararg.rb', line 19
def initialize(type)
raise "Can't have vararg optional type" if type.is_a? OptionalType
raise "Can't have vararg vararg type" if type.is_a? VarargType
raise "Can't have optional annotated type" if type.is_a? AnnotatedArgType
@type = type
super()
end
|
Instance Attribute Details
Returns the value of attribute type.
3
4
5
|
# File 'lib/rdl/types/vararg.rb', line 3
def type
@type
end
|
Class Method Details
8
|
# File 'lib/rdl/types/vararg.rb', line 8
alias :__new__ :new
|
.new(type) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/rdl/types/vararg.rb', line 11
def self.new(type)
t = @@cache[type]
return t if t
raise RuntimeError, "Attempt to create vararg type with non-type" unless type.is_a? Type
t = VarargType.__new__ type
return (@@cache[type] = t)
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
35
36
37
38
39
|
# File 'lib/rdl/types/vararg.rb', line 35
def ==(other)
return false if other.nil?
other = other.canonical
return (other.instance_of? VarargType) && (other.type == @type)
end
|
60
61
62
|
# File 'lib/rdl/types/vararg.rb', line 60
def copy
return VarargType.new(@type.copy)
end
|
64
65
66
|
# File 'lib/rdl/types/vararg.rb', line 64
def hash
return 59 + @type.hash
end
|
#instantiate(inst) ⇒ Object
Note: no member?, because these can only appear in MethodType, where they’re handled specially
52
53
54
|
# File 'lib/rdl/types/vararg.rb', line 52
def instantiate(inst)
return VarargType.new(@type.instantiate(inst))
end
|
#match(other) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/rdl/types/vararg.rb', line 43
def match(other)
other = other.canonical
other = other.type if other.instance_of? AnnotatedArgType
return true if other.instance_of? WildQuery
return (other.instance_of? VarargType) && (@type.match(other.type))
end
|
27
28
29
30
31
32
33
|
# File 'lib/rdl/types/vararg.rb', line 27
def to_s
if @type.instance_of? UnionType
"*(#{@type.to_s})"
else
"*#{@type.to_s}"
end
end
|
#vararg? ⇒ Boolean
68
69
70
|
# File 'lib/rdl/types/vararg.rb', line 68
def vararg?
return true
end
|
56
57
58
|
# File 'lib/rdl/types/vararg.rb', line 56
def widen
return VarargType.new(@type.widen)
end
|