Class: Tapioca::RBI::Sig

Inherits:
Node
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/rbi/model.rb,
lib/tapioca/rbi/printer.rb

Overview

Sorbet’s sigs

Instance Attribute Summary collapse

Attributes inherited from Node

#parent_tree

Instance Method Summary collapse

Methods inherited from Node

#detach, #group_kind, #oneline?, #print, #string

Constructor Details

#initialize(params: [], return_type: nil, is_abstract: false, is_override: false, is_overridable: false, type_params: []) ⇒ Sig

Returns a new instance of Sig.



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/tapioca/rbi/model.rb', line 267

def initialize(
  params: [],
  return_type: nil,
  is_abstract: false,
  is_override: false,
  is_overridable: false,
  type_params: []
)
  super()
  @params = params
  @return_type = return_type
  @is_abstract = is_abstract
  @is_override = is_override
  @is_overridable = is_overridable
  @type_params = type_params
end

Instance Attribute Details

#is_abstractObject

Returns the value of attribute is_abstract.



252
253
254
# File 'lib/tapioca/rbi/model.rb', line 252

def is_abstract
  @is_abstract
end

#is_overridableObject

Returns the value of attribute is_overridable.



252
253
254
# File 'lib/tapioca/rbi/model.rb', line 252

def is_overridable
  @is_overridable
end

#is_overrideObject

Returns the value of attribute is_override.



252
253
254
# File 'lib/tapioca/rbi/model.rb', line 252

def is_override
  @is_override
end

#paramsObject (readonly)

Returns the value of attribute params.



246
247
248
# File 'lib/tapioca/rbi/model.rb', line 246

def params
  @params
end

#return_typeObject

Returns the value of attribute return_type.



249
250
251
# File 'lib/tapioca/rbi/model.rb', line 249

def return_type
  @return_type
end

#type_paramsObject (readonly)

Returns the value of attribute type_params.



255
256
257
# File 'lib/tapioca/rbi/model.rb', line 255

def type_params
  @type_params
end

Instance Method Details

#<<(param) ⇒ Object



285
286
287
# File 'lib/tapioca/rbi/model.rb', line 285

def <<(param)
  @params << param
end

#accept_printer(v) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/tapioca/rbi/printer.rb', line 290

def accept_printer(v)
  v.printt("sig { ")
  v.print("abstract.") if is_abstract
  v.print("override.") if is_override
  v.print("overridable.") if is_overridable
  unless type_params.empty?
    v.print("type_parameters(")
    type_params.each_with_index do |param, index|
      v.print(":#{param}")
      v.print(", ") if index < type_params.length - 1
    end
    v.print(").")
  end
  unless params.empty?
    v.print("params(")
    params.each_with_index do |param, index|
      v.visit(param)
      v.print(", ") if index < params.length - 1
    end
    v.print(").")
  end
  if return_type && return_type != "void"
    v.print("returns(#{return_type})")
  else
    v.print("void")
  end
  v.printn(" }")
end