Class: RDL::Type::VarargType

Inherits:
Type show all
Defined in:
lib/rdl/types/vararg.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

Constructor Details

#initialize(type) ⇒ VarargType



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

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/rdl/types/vararg.rb', line 3

def type
  @type
end

Class Method Details

.__new__Object



8
# File 'lib/rdl/types/vararg.rb', line 8

alias :__new__ :new

.new(type) ⇒ Object

Raises:

  • (RuntimeError)


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) # assignment evaluates to t
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

:nodoc:



35
36
37
38
39
# File 'lib/rdl/types/vararg.rb', line 35

def ==(other) # :nodoc:
  return false if other.nil?
  other = other.canonical
  return (other.instance_of? VarargType) && (other.type == @type)
end

#copyObject



60
61
62
# File 'lib/rdl/types/vararg.rb', line 60

def copy
  return VarargType.new(@type.copy)
end

#hashObject

:nodoc:



64
65
66
# File 'lib/rdl/types/vararg.rb', line 64

def hash # :nodoc:
  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

#to_sObject



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

#widenObject



56
57
58
# File 'lib/rdl/types/vararg.rb', line 56

def widen
  return VarargType.new(@type.widen)
end