Class: RDL::Type::AnnotatedArgType

Inherits:
Type show all
Defined in:
lib/rdl/types/annotated_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) ⇒ AnnotatedArgType

Note: Named argument types aren’t hashconsed.

Raises:

  • (RuntimeError)


10
11
12
13
14
15
16
# File 'lib/rdl/types/annotated_arg.rb', line 10

def initialize(name, type)
  @name = name
  @type = type
  raise RuntimeError, "Attempt to create annotated type with non-type" unless type.is_a? Type
  raise RuntimeError, "Attempt to create doubly annotated type" if type.is_a? AnnotatedArgType
  super()
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rdl/types/annotated_arg.rb', line 5

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/rdl/types/annotated_arg.rb', line 6

def type
  @type
end

Instance Method Details

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

:nodoc:



22
23
24
25
26
# File 'lib/rdl/types/annotated_arg.rb', line 22

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

#copyObject



48
49
50
# File 'lib/rdl/types/annotated_arg.rb', line 48

def copy
  return AnnotatedArgType.new(@name, @type.copy)
end

#hashObject

doesn’t have a match method - queries shouldn’t have annotations in them



32
33
34
# File 'lib/rdl/types/annotated_arg.rb', line 32

def hash # :nodoc:
  return (57 + @name.hash) * @type.hash
end

#instantiate(inst) ⇒ Object



40
41
42
# File 'lib/rdl/types/annotated_arg.rb', line 40

def instantiate(inst)
  return AnnotatedArgType.new(@name, @type.instantiate(inst))
end

#member?(obj, *args) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/rdl/types/annotated_arg.rb', line 36

def member?(obj, *args)
  @type.member?(obj, *args)
end

#optional?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/rdl/types/annotated_arg.rb', line 52

def optional?
  return type.optional?
end

#to_sObject



18
19
20
# File 'lib/rdl/types/annotated_arg.rb', line 18

def to_s
  return "#{@type.to_s} #{@name}"
end

#vararg?Boolean

Returns:

  • (Boolean)


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

def vararg?
  return type.vararg?
end

#widenObject



44
45
46
# File 'lib/rdl/types/annotated_arg.rb', line 44

def widen
  return AnnotatedArgType.new(@name, @type.widen)
end