Class: CodeMiner::Substitution
- Inherits:
-
Object
- Object
- CodeMiner::Substitution
- Defined in:
- lib/codeminer/substitution.rb
Defined Under Namespace
Classes: Value
Instance Method Summary collapse
-
#initialize(node) ⇒ Substitution
constructor
A new instance of Substitution.
- #substitute(*substitutions) ⇒ Object
Constructor Details
#initialize(node) ⇒ Substitution
Returns a new instance of Substitution.
17 18 19 |
# File 'lib/codeminer/substitution.rb', line 17 def initialize(node) @node = node end |
Instance Method Details
#substitute(*substitutions) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/codeminer/substitution.rb', line 21 def substitute(*substitutions) @node.src.tap do |src| substitutions.sort.inject(0) do |offset, substitution| src[substitution_range(substitution, offset - substitution.column_adjustment.to_i)] = substitution.replacement offset + (substitution.replacement.length - substitution.node.src.length) end end end |