Module: Mutant::AST

Defined in:
lib/mutant/ast.rb,
lib/mutant/ast/meta.rb,
lib/mutant/ast/sexp.rb,
lib/mutant/ast/nodes.rb,
lib/mutant/ast/types.rb,
lib/mutant/ast/named_children.rb,
lib/mutant/ast/node_predicates.rb

Overview

AST helpers

Defined Under Namespace

Modules: Meta, NamedChildren, NodePredicates, Nodes, Sexp, Types

Class Method Summary collapse

Class Method Details

.find_last_path(node) {|Parser::AST::Node| ... } ⇒ Parser::AST::Node?

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.

Find last node satisfying predicate (as block)

Yields:

  • (Parser::AST::Node)

Yield Returns:

  • (Boolean)

    true in case node satisfies predicate

Returns:

  • (Parser::AST::Node)

    if satisfying node is found

  • (nil)

    otherwise


46
47
48
49
50
51
52
53
54
55
# File 'lib/mutant/ast.rb', line 46

def self.find_last_path(node, &predicate)
  fail ArgumentError, 'block expected' unless block_given?
  path = []
  walk(node, [node]) do |candidate, stack|
    if predicate.call(candidate, &predicate)
      path = stack.dup
    end
  end
  path
end