class RubyDetective::AST::Nodes::ConstantReferenceNode

Constants

CONSTANT_NAME_INDEX
NESTED_CONSTANT_INDEX

Recursively builds the constant path by traversing it's children, that way we can compose a path composed of multiple namespaces, for example: Foo::Bar::Batz as [:Foo, :Bar, :Batz].

Public Instance Methods

constant_name() click to toggle source
# File lib/ruby_detective/ast/nodes/constant_reference_node.rb, line 6
def constant_name
  children[CONSTANT_NAME_INDEX].value
end
constant_path() click to toggle source
# File lib/ruby_detective/ast/nodes/constant_reference_node.rb, line 21
def constant_path
  nested_constant = children[NESTED_CONSTANT_INDEX]

  if nested_constant.constant_reference_node?
    nested_constant.constant_path + [constant_name]
  elsif nested_constant.absolute_path_sign_node?
    # This is used to signify that the constant path was forced to start
    # from the root, for example: "::Foo::Bar"
    [:"::"] + [constant_name]
  else
    [constant_name]
  end
end
top_level_constant?() click to toggle source

A top level constant is for example the “Bar” from “Foo::Bar”. We access it by checking if the parent is another constant, if it is it means the constant is a nested one and not top level.

# File lib/ruby_detective/ast/nodes/constant_reference_node.rb, line 13
def top_level_constant?
  !parent_node.constant_reference_node?
end
type() click to toggle source
# File lib/ruby_detective/ast/nodes/constant_reference_node.rb, line 35
def type
  :constant
end