Class: RBS::Dynamic::Builder::Methods

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/dynamic/builder/methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, kind: :instance) ⇒ Methods

Returns a new instance of Methods.



107
108
109
110
111
# File 'lib/rbs/dynamic/builder/methods.rb', line 107

def initialize(name, kind: :instance)
  @name = name
  @sigs = []
  @kind = kind
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



105
106
107
# File 'lib/rbs/dynamic/builder/methods.rb', line 105

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



104
105
106
# File 'lib/rbs/dynamic/builder/methods.rb', line 104

def name
  @name
end

#sigsObject (readonly)

Returns the value of attribute sigs.



103
104
105
# File 'lib/rbs/dynamic/builder/methods.rb', line 103

def sigs
  @sigs
end

Instance Method Details

#<<(sig) ⇒ Object



113
114
115
# File 'lib/rbs/dynamic/builder/methods.rb', line 113

def <<(sig)
  sigs << sig
end

#buildObject



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rbs/dynamic/builder/methods.rb', line 117

def build
  RBS::AST::Members::MethodDefinition.new(
    name: name,
    kind: kind,
    types: types,
    annotations: [],
    location: nil,
    comment: comment,
    overload: false,
    visibility: sigs.last[:visibility]
  )
end

#commentObject



136
137
138
139
140
141
142
# File 'lib/rbs/dynamic/builder/methods.rb', line 136

def comment
  <<~EOS.comment if sigs.last[:source_location] && sigs.any? { _1[:reference_location] }
    source location: #{sigs.last[:source_location]}
    reference location:
    #{sigs.map { "  #{name}#{_1.method_type} #{_1[:reference_location]}" }.uniq.join("\n")}
  EOS
end

#typesObject



130
131
132
133
134
# File 'lib/rbs/dynamic/builder/methods.rb', line 130

def types
  sigs.zip_sig.map { |sig|
    sig.method_type
  }
end