class RBI::Sig
Sorbet's sigs
Attributes
checked[RW]
is_abstract[RW]
is_overridable[RW]
is_override[RW]
params[R]
return_type[RW]
type_params[R]
Public Class Methods
new( params: [], return_type: nil, is_abstract: false, is_override: false, is_overridable: false, type_params: [], checked: nil, loc: nil, &block )
click to toggle source
Calls superclass method
RBI::Node::new
# File lib/rbi/model.rb, line 937 def initialize( params: [], return_type: nil, is_abstract: false, is_override: false, is_overridable: false, type_params: [], checked: nil, loc: nil, &block ) 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 block&.call(self) end
Public Instance Methods
<<(param)
click to toggle source
# File lib/rbi/model.rb, line 960 def <<(param) @params << param end
==(other)
click to toggle source
# File lib/rbi/model.rb, line 965 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)
click to toggle source
# File lib/rbi/printer.rb, line 545 def accept_printer(v) v.printl("# #{loc}") if loc && v.print_locs if oneline? v.printt("sig { ") else v.printl("sig do") v.indent end 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? if inline_params? v.print("params(") params.each_with_index do |param, index| v.print(", ") if index > 0 v.visit(param) end v.print(").") else v.printl("params(") v.indent params.each_with_index do |param, pindex| v.printt v.visit(param) v.print(",") if pindex < params.size - 1 param.comments.each_with_index do |comment, cindex| if cindex == 0 v.print(" ") else param.print_comment_leading_space(v, last: pindex == params.size - 1) end v.print("# #{comment.text.strip}") end v.printn end v.dedent v.printt(").") end end if return_type && return_type != "void" v.print("returns(#{return_type})") else v.print("void") end if checked v.print(".checked(:#{checked})") end if oneline? v.printn(" }") else v.printn v.dedent v.printl("end") end end
inline_params?()
click to toggle source
# File lib/rbi/printer.rb, line 616 def inline_params? params.all? { |p| p.comments.empty? } end
oneline?()
click to toggle source
# File lib/rbi/printer.rb, line 611 def oneline? inline_params? end