Class: Spoom::Source::Rewriter
- Inherits:
-
Object
- Object
- Spoom::Source::Rewriter
- Defined in:
- lib/spoom/source/rewriter.rb
Instance Method Summary collapse
-
#<<(other) ⇒ Object
: (Edit) -> void.
-
#initialize ⇒ Rewriter
constructor
: -> void.
-
#rewrite!(bytes) ⇒ Object
: (Array) -> void.
Constructor Details
#initialize ⇒ Rewriter
: -> void
148 149 150 |
# File 'lib/spoom/source/rewriter.rb', line 148 def initialize @edits = [] #: Array[Edit] end |
Instance Method Details
#<<(other) ⇒ Object
: (Edit) -> void
153 154 155 |
# File 'lib/spoom/source/rewriter.rb', line 153 def <<(other) @edits << other end |
#rewrite!(bytes) ⇒ Object
: (Array) -> void
158 159 160 161 162 163 164 |
# File 'lib/spoom/source/rewriter.rb', line 158 def rewrite!(bytes) # To avoid remapping positions after each edit, # we sort the changes by position and apply them in reverse order. @edits.sort_by(&:range).reverse_each do |edit| edit.apply(bytes) end end |