Class: Steep::Names::Module

Inherits:
Base
  • Object
show all
Defined in:
lib/steep/names.rb

Instance Attribute Summary

Attributes inherited from Base

#location, #name, #namespace

Class Method Summary collapse

Methods inherited from Base

#==, #absolute!, #absolute?, #hash, #in_namespace, #initialize, parse, #relative?, #to_s

Constructor Details

This class inherits a constructor from Steep::Names::Base

Class Method Details

.from_node(node) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/steep/names.rb', line 57

def self.from_node(node)
  case node.type
  when :const, :casgn
    namespace = namespace_from_node(node.children[0]) or return
    name = node.children[1]
    new(namespace: namespace, name: name)
  end
end

.namespace_from_node(node) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/steep/names.rb', line 66

def self.namespace_from_node(node)
  case node&.type
  when nil
    AST::Namespace.empty
  when :cbase
    AST::Namespace.root
  when :const
    namespace_from_node(node.children[0])&.yield_self do |parent|
      parent.append(node.children[1])
    end
  end
end