Class: RBI::Sig

Inherits:
NodeWithComments show all
Defined in:
lib/rbi/model.rb

Overview

Sorbet’s sigs

Instance Attribute Summary collapse

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from NodeWithComments

#annotations, #comments?, #merge_with, #version_requirements

Methods inherited from Node

#compatible_with?, #detach, #merge_with, #parent_conflict_tree, #parent_scope, #print, #rbs_print, #rbs_string, #replace, #satisfies_version?, #string

Constructor Details

#initialize(params: nil, return_type: "void", is_abstract: false, is_override: false, is_overridable: false, is_final: false, allow_incompatible_override: false, allow_incompatible_override_visibility: false, without_runtime: false, type_params: nil, checked: nil, loc: nil, comments: nil, &block) ⇒ Sig

: ( | ?params: Array?, | ?return_type: (Type | String), | ?is_abstract: bool, | ?is_override: bool, | ?is_overridable: bool, | ?is_final: bool, | ?allow_incompatible_override: bool, | ?allow_incompatible_override_visibility: bool, | ?without_runtime: bool, | ?type_params: Array?, | ?checked: Symbol?, | ?loc: Loc?, | ?comments: Array? | ) ?{ (Sig node) -> void } -> void



964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
# File 'lib/rbi/model.rb', line 964

def initialize(
  params: nil,
  return_type: "void",
  is_abstract: false,
  is_override: false,
  is_overridable: false,
  is_final: false,
  allow_incompatible_override: false,
  allow_incompatible_override_visibility: false,
  without_runtime: false,
  type_params: nil,
  checked: nil,
  loc: nil,
  comments: nil,
  &block
)
  super(loc: loc, comments: comments)
  @params = params #: Array[SigParam]?
  @return_type = return_type
  @is_abstract = is_abstract
  @is_override = is_override
  @is_overridable = is_overridable
  @is_final = is_final
  @allow_incompatible_override = allow_incompatible_override
  @allow_incompatible_override_visibility = allow_incompatible_override_visibility
  @without_runtime = without_runtime
  @type_params = type_params #: Array[String]?
  @checked = checked
  block&.call(self)
end

Instance Attribute Details

#allow_incompatible_overrideObject

: bool



928
929
930
# File 'lib/rbi/model.rb', line 928

def allow_incompatible_override
  @allow_incompatible_override
end

#allow_incompatible_override_visibilityObject

: bool



931
932
933
# File 'lib/rbi/model.rb', line 931

def allow_incompatible_override_visibility
  @allow_incompatible_override_visibility
end

#checkedObject

: Symbol?



947
948
949
# File 'lib/rbi/model.rb', line 947

def checked
  @checked
end

#is_abstractObject

: bool



916
917
918
# File 'lib/rbi/model.rb', line 916

def is_abstract
  @is_abstract
end

#is_finalObject

: bool



925
926
927
# File 'lib/rbi/model.rb', line 925

def is_final
  @is_final
end

#is_overridableObject

: bool



922
923
924
# File 'lib/rbi/model.rb', line 922

def is_overridable
  @is_overridable
end

#is_overrideObject

: bool



919
920
921
# File 'lib/rbi/model.rb', line 919

def is_override
  @is_override
end

#return_typeObject

: (Type | String)



913
914
915
# File 'lib/rbi/model.rb', line 913

def return_type
  @return_type
end

#without_runtimeObject

: bool



934
935
936
# File 'lib/rbi/model.rb', line 934

def without_runtime
  @without_runtime
end

Instance Method Details

#<<(param) ⇒ Object

: (SigParam param) -> void



996
997
998
# File 'lib/rbi/model.rb', line 996

def <<(param)
  params << param
end

#==(other) ⇒ Object

: (Object other) -> bool



1006
1007
1008
1009
1010
1011
1012
# File 'lib/rbi/model.rb', line 1006

def ==(other)
  return false unless other.is_a?(Sig)

  params == other.params && return_type.to_s == other.return_type.to_s && is_abstract == other.is_abstract &&
    is_override == other.is_override && is_overridable == other.is_overridable && is_final == other.is_final &&
    without_runtime == other.without_runtime && type_params == other.type_params && checked == other.checked
end

#add_param(name, type) ⇒ Object

: (String name, (Type | String) type) -> void



1001
1002
1003
# File 'lib/rbi/model.rb', line 1001

def add_param(name, type)
  params << SigParam.new(name, type)
end

#paramsObject

: -> Array



908
909
910
# File 'lib/rbi/model.rb', line 908

def params
  @params ||= []
end

#type_paramsObject

: -> Array



937
938
939
# File 'lib/rbi/model.rb', line 937

def type_params
  @type_params ||= []
end

#type_params?Boolean

: -> bool

Returns:

  • (Boolean)


942
943
944
# File 'lib/rbi/model.rb', line 942

def type_params?
  !@type_params.nil? && !@type_params.empty?
end