Module: ActiveMutator::Splicer
- Defined in:
- lib/active_mutator/splicer.rb
Class Method Summary collapse
-
.apply(source, edits) ⇒ Object
Applies edits to source by byte offset.
Class Method Details
.apply(source, edits) ⇒ Object
Applies edits to source by byte offset. Edits are applied back-to-front so earlier offsets never drift.
5 6 7 8 9 10 11 |
# File 'lib/active_mutator/splicer.rb', line 5 def self.apply(source, edits) bytes = source.b edits.sort_by { |e| -e.range.begin }.each do |e| bytes[e.range] = e.replacement.b end bytes.force_encoding(source.encoding) end |