Class: RBS::Definition::Method::TypeDef

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/definition.rb,
sig/definition.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, member:, defined_in:, implemented_in:, overload_annotations: []) ⇒ Object

overload_annotations is ignored.



54
55
56
57
58
59
60
61
62
# File 'sig/definition.rbs', line 54

def initialize(type:, member:, defined_in:, implemented_in:, overload_annotations: [])
  @type = type
  @member = member
  @defined_in = defined_in
  @implemented_in = implemented_in
  @member_annotations = []
  @overload_annotations = []
  @annotations = []
end

Instance Attribute Details

#annotationsObject (readonly)

Returns the value of attribute annotations.



38
39
40
# File 'lib/rbs/definition.rb', line 38

def annotations
  @annotations
end

#defined_inTypeName (readonly)

Returns the value of attribute defined_in.

Returns:



34
35
36
# File 'lib/rbs/definition.rb', line 34

def defined_in
  @defined_in
end

#implemented_inTypeName? (readonly)

Returns the value of attribute implemented_in.

Returns:



35
36
37
# File 'lib/rbs/definition.rb', line 35

def implemented_in
  @implemented_in
end

#membermethod_member (readonly)

Returns the value of attribute member.

Returns:

  • (method_member)


33
34
35
# File 'lib/rbs/definition.rb', line 33

def member
  @member
end

#member_annotationsArray[AST::Annotation] (readonly)

Annotations given to the method definition syntax

If the method have multiple syntaxes, union of the annotations to the member will be included, without dedup.

The value should be updated during setup.

Returns:



42
43
44
# File 'sig/definition.rbs', line 42

def member_annotations
  @member_annotations
end

#overload_annotationsArray[AST::Annotation] (readonly)

Annotations given to the overload associated to the method type

The value should be updated during setup.

Returns:



48
49
50
# File 'sig/definition.rbs', line 48

def overload_annotations
  @overload_annotations
end

#typeMethodType (readonly)

Returns the value of attribute type.

Returns:



32
33
34
# File 'lib/rbs/definition.rb', line 32

def type
  @type
end

Instance Method Details

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



50
51
52
53
54
55
56
# File 'lib/rbs/definition.rb', line 50

def ==(other)
  other.is_a?(TypeDef) &&
    other.type == type &&
    other.member == member &&
    other.defined_in == defined_in &&
    other.implemented_in == implemented_in
end

#commentAST::Comment?

Returns:



64
65
66
67
68
69
70
71
# File 'lib/rbs/definition.rb', line 64

def comment
  case member
  when AST::Members::Base
    member.comment
  when AST::Ruby::Members::Base
    member.leading_comment&.as_comment
  end
end

#each_annotationvoid #each_annotationEnumerator[AST::Annotation]

Yields member and overload annotations, without dedup

Member annotation yields first.

Overloads:

  • #each_annotationvoid

    This method returns an undefined value.

  • #each_annotationEnumerator[AST::Annotation]

    Returns:

Yields:

Yield Parameters:

Yield Returns:

  • (void)


78
79
80
81
82
83
84
85
# File 'sig/definition.rbs', line 78

def each_annotation(&block)
  if block
    member_annotations.each(&block)
    overload_annotations.each(&block)
  else
    enum_for :each_annotation
  end
end

#hashObject



60
61
62
# File 'lib/rbs/definition.rb', line 60

def hash
  self.class.hash ^ type.hash ^ member.hash ^ defined_in.hash ^ implemented_in.hash
end

#overload?Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
# File 'lib/rbs/definition.rb', line 80

def overload?
  case mem = member
  when AST::Members::MethodDefinition
    mem.overloading?
  else
    false
  end
end

#update(type: self.type, member: self.member, defined_in: self.defined_in, implemented_in: self.implemented_in) ⇒ TypeDef

Parameters:

  • type: (MethodType) (defaults to: self.type)
  • member: (method_member) (defaults to: self.member)
  • defined_in: (TypeName) (defaults to: self.defined_in)
  • implemented_in: (TypeName, nil) (defaults to: self.implemented_in)

Returns:



73
74
75
76
77
78
# File 'lib/rbs/definition.rb', line 73

def update(type: self.type, member: self.member, defined_in: self.defined_in, implemented_in: self.implemented_in)
  TypeDef.new(type: type, member: member, defined_in: defined_in, implemented_in: implemented_in).tap do |type_def|
    type_def.overload_annotations.replace(self.overload_annotations)
    type_def.member_annotations.replace(self.member_annotations)
  end
end