Module: Evilution::AST::SourceSurgeon Private

Defined in:
lib/evilution/ast/source_surgeon.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Class Method Details

.apply(source, offset:, length:, replacement:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
21
22
23
24
# File 'lib/evilution/ast/source_surgeon.rb', line 18

def self.apply(source, offset:, length:, replacement:)
  binary = source.b
  binary[offset, length] = replacement.b
  mutated = binary.force_encoding(source.encoding)
  status = Prism.parse(mutated).success? ? :ok : :unparseable
  Result.new(source: mutated, status: status).freeze
end