Class: RBI::Sig

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

Overview

Sorbet’s sigs

Instance Attribute Summary collapse

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from Node

#compatible_with?, #detach, #group_kind, #merge_with, #oneline?, #parent_conflict_tree, #parent_scope, #print, #replace, #string

Constructor Details

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

Returns a new instance of Sig.



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'lib/rbi/model.rb', line 645

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

Instance Attribute Details

#checkedObject

Returns the value of attribute checked.



631
632
633
# File 'lib/rbi/model.rb', line 631

def checked
  @checked
end

#is_abstractObject

Returns the value of attribute is_abstract.



625
626
627
# File 'lib/rbi/model.rb', line 625

def is_abstract
  @is_abstract
end

#is_overridableObject

Returns the value of attribute is_overridable.



625
626
627
# File 'lib/rbi/model.rb', line 625

def is_overridable
  @is_overridable
end

#is_overrideObject

Returns the value of attribute is_override.



625
626
627
# File 'lib/rbi/model.rb', line 625

def is_override
  @is_override
end

#paramsObject (readonly)

Returns the value of attribute params.



619
620
621
# File 'lib/rbi/model.rb', line 619

def params
  @params
end

#return_typeObject

Returns the value of attribute return_type.



622
623
624
# File 'lib/rbi/model.rb', line 622

def return_type
  @return_type
end

#type_paramsObject (readonly)

Returns the value of attribute type_params.



628
629
630
# File 'lib/rbi/model.rb', line 628

def type_params
  @type_params
end

Instance Method Details

#<<(param) ⇒ Object



666
667
668
# File 'lib/rbi/model.rb', line 666

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

#==(other) ⇒ Object



671
672
673
674
675
676
# File 'lib/rbi/model.rb', line 671

def ==(other)
  return false unless other.is_a?(Sig)
  params == other.params && return_type == other.return_type && is_abstract == other.is_abstract &&
    is_override == other.is_override && is_overridable == other.is_overridable &&
    type_params == other.type_params && checked == other.checked
end

#accept_printer(v) ⇒ Object



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/rbi/printer.rb', line 506

def accept_printer(v)
  v.printl("# #{loc}") if loc && v.print_locs
  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
  if checked
    v.print(".checked(:#{checked})")
  end
  v.printn(" }")
end