Class: RDL::Type::BoundArgType
- Inherits:
-
Type
show all
- Defined in:
- lib/rdl/types/bound_arg.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Type
#canonical, leq, #nil_type?, #to_contract
Constructor Details
#initialize(name, type) ⇒ BoundArgType
Note: Named argument types aren’t hashconsed.
10
11
12
13
14
15
16
17
18
|
# File 'lib/rdl/types/bound_arg.rb', line 10
def initialize(name, type)
@name = name
@type = type
raise RuntimeError, "Attempt to create bound type with non-type" unless type.is_a? Type
raise RuntimeError, "Attempt to create doubly annotated type" if (type.is_a?(BoundArgType) || type.is_a?(AnnotatedArgType))
raise RuntimeError, "Cannot create bound type with optional type" if type.is_a? OptionalType
raise RuntimeError, "Cannot create bound type with variable argument type" if type.is_a? VarargType
super()
end
|
Instance Attribute Details
Returns the value of attribute name.
5
6
7
|
# File 'lib/rdl/types/bound_arg.rb', line 5
def name
@name
end
|
Returns the value of attribute type.
6
7
8
|
# File 'lib/rdl/types/bound_arg.rb', line 6
def type
@type
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
24
25
26
27
28
|
# File 'lib/rdl/types/bound_arg.rb', line 24
def ==(other) return false if other.nil?
other = other.canonical
return (other.instance_of? BoundArgType) && (other.name == @name) && (other.type == @type)
end
|
50
51
52
|
# File 'lib/rdl/types/bound_arg.rb', line 50
def copy
return BoundArgType.new(@name, @type.copy)
end
|
doesn’t have a match method - queries shouldn’t have annotations in them
34
35
36
|
# File 'lib/rdl/types/bound_arg.rb', line 34
def hash return (57 + @name.hash) * @type.hash
end
|
#instantiate(inst) ⇒ Object
42
43
44
|
# File 'lib/rdl/types/bound_arg.rb', line 42
def instantiate(inst)
return BoundArgType.new(@name, @type.instantiate(inst))
end
|
#member?(obj, *args) ⇒ Boolean
38
39
40
|
# File 'lib/rdl/types/bound_arg.rb', line 38
def member?(obj, *args)
@type.member?(obj, *args)
end
|
#optional? ⇒ Boolean
54
55
56
|
# File 'lib/rdl/types/bound_arg.rb', line 54
def optional?
return type.optional?
end
|
20
21
22
|
# File 'lib/rdl/types/bound_arg.rb', line 20
def to_s
return "#{@name}<::#{@type.to_s}"
end
|
#vararg? ⇒ Boolean
58
59
60
|
# File 'lib/rdl/types/bound_arg.rb', line 58
def vararg?
return type.vararg?
end
|
46
47
48
|
# File 'lib/rdl/types/bound_arg.rb', line 46
def widen
return BoundArgType.new(@name, @type.widen)
end
|