Module: Mutant::AST Private

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/meta/send.rb,
lib/mutant/ast/meta/const.rb,
lib/mutant/ast/meta/optarg.rb,
lib/mutant/ast/meta/symbol.rb,
lib/mutant/ast/meta/resbody.rb,
lib/mutant/ast/named_children.rb,
lib/mutant/ast/node_predicates.rb,
lib/mutant/ast/find_metaclass_containing.rb

Overview

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.

AST helpers

Defined Under Namespace

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

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



19
20
21
22
23
24
25
26
27
28
# File 'lib/mutant/ast.rb', line 19

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)
      path = stack.dup
    end
  end
  path
end