Class: SyntaxTree::Index::EntryComments
- Inherits:
-
Object
- Object
- SyntaxTree::Index::EntryComments
- Includes:
- Enumerable
- Defined in:
- lib/syntax_tree/index.rb
Overview
This class handles parsing comments from Ruby source code in the case that we use the instruction sequence backend. Because the instruction sequence backend doesn’t provide comments (since they are dropped) we provide this interface to lazily parse them out.
Instance Attribute Summary collapse
-
#file_comments ⇒ Object
readonly
Returns the value of attribute file_comments.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(file_comments, location) ⇒ EntryComments
constructor
A new instance of EntryComments.
Constructor Details
#initialize(file_comments, location) ⇒ EntryComments
Returns a new instance of EntryComments.
131 132 133 134 |
# File 'lib/syntax_tree/index.rb', line 131 def initialize(file_comments, location) @file_comments = file_comments @location = location end |
Instance Attribute Details
#file_comments ⇒ Object (readonly)
Returns the value of attribute file_comments.
129 130 131 |
# File 'lib/syntax_tree/index.rb', line 129 def file_comments @file_comments end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
129 130 131 |
# File 'lib/syntax_tree/index.rb', line 129 def location @location end |
Instance Method Details
#each(&block) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/syntax_tree/index.rb', line 136 def each(&block) line = location.line - 1 result = [] while line >= 0 && (comment = file_comments.comments[line]) result.unshift(comment) line -= 1 end result.each(&block) end |