Class: RBI::SigParam

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

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, #merge_with, #oneline?

Methods inherited from Node

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

Constructor Details

#initialize(name, type, loc: nil, comments: [], &block) ⇒ SigParam

Returns a new instance of SigParam.



1101
1102
1103
1104
1105
1106
# File 'lib/rbi/model.rb', line 1101

def initialize(name, type, loc: nil, comments: [], &block)
  super(loc: loc, comments: comments)
  @name = name
  @type = type
  block&.call(self)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



1090
1091
1092
# File 'lib/rbi/model.rb', line 1090

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



1090
1091
1092
# File 'lib/rbi/model.rb', line 1090

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



1109
1110
1111
# File 'lib/rbi/model.rb', line 1109

def ==(other)
  other.is_a?(SigParam) && name == other.name && type == other.type
end

#accept_printer(v) ⇒ Object



683
684
685
# File 'lib/rbi/printer.rb', line 683

def accept_printer(v)
  v.print("#{name}: #{type}")
end

#comments_linesObject



696
697
698
# File 'lib/rbi/printer.rb', line 696

def comments_lines
  comments.flat_map { |comment| comment.text.lines.map(&:strip) }
end


688
689
690
691
692
693
# File 'lib/rbi/printer.rb', line 688

def print_comment_leading_space(v, last:)
  v.printn
  v.printt
  v.print(" " * (name.size + type.size + 3))
  v.print(" ") unless last
end