Method: Synvert::Core::Rewriter::Instance#replace

Defined in:
lib/synvert/core/rewriter/instance.rb

#replace(*selectors, with:) ⇒ Object

It replaces the code of specified child nodes.

Examples:

# assert(object.empty?)
# =>
# assert_empty(object)
with_node type: 'send', receiver: nil, message: 'assert', arguments: { size: 1, first: { type: 'send', message: 'empty?', arguments: { size: 0 } } } do
  replace :message, with: 'assert_empty'
  replace :arguments, with: '{{arguments.first.receiver}}'
end

Parameters:

  • selectors (Array<Symbol>)

    selector names of child node.

  • with (String)

    code need to be replaced with.



356
357
358
# File 'lib/synvert/core/rewriter/instance.rb', line 356

def replace(*selectors, with:)
  @current_mutation.replace(@current_node, *selectors, with: with)
end