Class: RBI::NodeWithComments

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

Instance Attribute Summary collapse

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initialize(loc: nil, comments: []) ⇒ NodeWithComments

Returns a new instance of NodeWithComments.



93
94
95
96
# File 'lib/rbi/model.rb', line 93

def initialize(loc: nil, comments: [])
  super(loc: loc)
  @comments = comments
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



90
91
92
# File 'lib/rbi/model.rb', line 90

def comments
  @comments
end

Instance Method Details

#annotationsObject



99
100
101
102
103
# File 'lib/rbi/model.rb', line 99

def annotations
  comments
    .select { |comment| comment.text.start_with?("@") }
    .map { |comment| T.must(comment.text[1..]) }
end

#merge_with(other) ⇒ Object



311
312
313
314
315
316
317
# File 'lib/rbi/rewriters/merge_trees.rb', line 311

def merge_with(other)
  return unless other.is_a?(NodeWithComments)

  other.comments.each do |comment|
    comments << comment unless comments.include?(comment)
  end
end

#oneline?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/rbi/printer.rb', line 188

def oneline?
  comments.empty?
end