Class: Mutant::AST::FindMetaclassContaining Private

Inherits:
Object
  • Object
show all
Includes:
NodePredicates, Procto
Defined in:
lib/mutant/ast/find_metaclass_containing.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Given an AST, finds the sclass that directly(-ish) contains the provided node. This won’t match arbitrarily complex structures - it only searches the first level deep (no begins-in-begins, for example). This is in keeping with mutant generally not supporting ‘weird’ syntax. Descending into ‘begin’ nodes is supported because these are generated for the one-line syntax class << self; def foo; end

Constant Summary collapse

SCLASS_BODY_INDEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1

Instance Method Summary collapse

Methods included from Procto

included

Instance Method Details

#callParser::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 metaclass node containing target node

Returns:

  • (Parser::AST::Node, nil)


24
25
26
27
28
29
30
# File 'lib/mutant/ast/find_metaclass_containing.rb', line 24

def call
  Structure.for(ast.node.type).each_node(ast.node) do |current|
    return current if n_sclass?(current) && metaclass_of?(current)
  end

  nil
end