Class: RBI::NodeWithComments Abstract
- Defined in:
- lib/rbi/model.rb,
lib/rbi/rewriters/merge_trees.rb,
lib/rbi/rewriters/filter_versions.rb
Overview
This class is abstract.
Direct Known Subclasses
Attr, Const, Helper, Method, Mixin, Param, RequiresAncestor, Send, Sig, SigParam, TEnumValue, TStructField, Tree, TypeMember, Visibility
Instance Attribute Summary collapse
-
#comments ⇒ Object
: -> Array.
Attributes inherited from Node
Instance Method Summary collapse
-
#annotations ⇒ Object
: -> Array.
-
#comments? ⇒ Boolean
Returns true if this node has any comments, without allocating an empty array for nodes that have never had comments set.
-
#initialize(loc: nil, comments: nil) ⇒ NodeWithComments
constructor
: (?loc: Loc?, ?comments: Array?) -> void.
-
#merge_with(other) ⇒ Object
: (Node other) -> void.
-
#version_requirements ⇒ Object
: -> Array.
Methods inherited from Node
#compatible_with?, #detach, #parent_conflict_tree, #parent_scope, #print, #rbs_print, #rbs_string, #replace, #satisfies_version?, #string
Constructor Details
#initialize(loc: nil, comments: nil) ⇒ NodeWithComments
: (?loc: Loc?, ?comments: Array?) -> void
105 106 107 108 |
# File 'lib/rbi/model.rb', line 105 def initialize(loc: nil, comments: nil) super(loc: loc) @comments = comments #: Array[Comment]? end |
Instance Attribute Details
#comments ⇒ Object
: -> Array
93 94 95 |
# File 'lib/rbi/model.rb', line 93 def comments @comments ||= [] end |
Instance Method Details
#annotations ⇒ Object
: -> Array
111 112 113 114 115 116 117 |
# File 'lib/rbi/model.rb', line 111 def annotations comments .select { |comment| comment.text.start_with?("@") } .map do |comment| comment.text[1..] #: as !nil end end |
#comments? ⇒ Boolean
Returns true if this node has any comments, without allocating an empty array for nodes that have never had comments set. : -> bool
100 101 102 |
# File 'lib/rbi/model.rb', line 100 def comments? !@comments.nil? && !@comments.empty? end |
#merge_with(other) ⇒ Object
: (Node other) -> void
325 326 327 328 329 330 331 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 325 def merge_with(other) return unless other.is_a?(NodeWithComments) other.comments.each do |comment| comments << comment unless comments.include?(comment) end end |
#version_requirements ⇒ Object
: -> Array
101 102 103 104 105 106 107 108 |
# File 'lib/rbi/rewriters/filter_versions.rb', line 101 def version_requirements annotations.select do |annotation| annotation.start_with?(Rewriters::FilterVersions::VERSION_PREFIX) end.map do |annotation| versions = annotation.delete_prefix(Rewriters::FilterVersions::VERSION_PREFIX).split(/, */) Gem::Requirement.new(versions) end end |