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.
156 157 158 159 |
# File 'lib/syntax_tree/index.rb', line 156 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.
154 155 156 |
# File 'lib/syntax_tree/index.rb', line 154 def file_comments @file_comments end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
154 155 156 |
# File 'lib/syntax_tree/index.rb', line 154 def location @location end |
Instance Method Details
#each(&block) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/syntax_tree/index.rb', line 161 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 |