Method: Synvert::Core::Rewriter::Instance#if_only_exist_node

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

#if_only_exist_node(rules, &block) ⇒ Object

Parse if_only_exist_node dsl, it creates a Synvert::Core::Rewriter::IfOnlyExistCondition to check if current node has only one child node and the child node matches rules, if so, then continue operating on each matching ast node.

Examples:

# it { should matcher }
with_node type: 'block', caller: { message: 'it' } do
  if_only_exist_node type: 'send', receiver: nil, message: 'should' do
  end
end

Parameters:

  • rules (Hash)

    rules to check mathing ast nodes.

  • block (Block)

    block code to continue operating on the matching nodes.



214
215
216
# File 'lib/synvert/core/rewriter/instance.rb', line 214

def if_only_exist_node(rules, &block)
  Rewriter::IfOnlyExistCondition.new(self, rules, &block).process
end