Class: SeeingIsBelieving::Binary::CommentLines
- Inherits:
-
Object
- Object
- SeeingIsBelieving::Binary::CommentLines
- Defined in:
- lib/seeing_is_believing/binary/comment_lines.rb
Overview
takes a body and a block passes the block the line the block returns the comment to add at the end of it
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(code, &commenter) ⇒ CommentLines
constructor
A new instance of CommentLines.
Constructor Details
#initialize(code, &commenter) ⇒ CommentLines
Returns a new instance of CommentLines.
14 15 16 |
# File 'lib/seeing_is_believing/binary/comment_lines.rb', line 14 def initialize(code, &commenter) self.code, self.commenter = code, commenter end |
Class Method Details
.call(code, &commenter) ⇒ Object
10 11 12 |
# File 'lib/seeing_is_believing/binary/comment_lines.rb', line 10 def self.call(code, &commenter) new(code, &commenter).call end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/seeing_is_believing/binary/comment_lines.rb', line 18 def call @call ||= begin commentable_lines = CommentableLines.new code commentable_lines.call.each do |line_number, (index_of_newline, col)| first_index = last_index = index_of_newline first_index -= 1 while first_index > 0 && code[first_index-1] != "\n" comment_text = commenter.call code[first_index...last_index], line_number range = Parser::Source::Range.new(commentable_lines.buffer, first_index, last_index) commentable_lines.rewriter.insert_after range, comment_text end commentable_lines.rewriter.process end end |