Module: RBS::AST::Ruby::Helpers::ConstantHelper

Included in:
Declarations::Base, InlineParser::Parser
Defined in:
lib/rbs/ast/ruby/helpers/constant_helper.rb

Class Method Summary collapse

Class Method Details

.constant_as_type_name(node) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rbs/ast/ruby/helpers/constant_helper.rb', line 10

def constant_as_type_name(node)
  case node
  when Prism::ConstantPathNode, Prism::ConstantReadNode
    begin
      TypeName.parse(node.full_name)
    rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError
      nil
    end
  when Prism::ConstantWriteNode
    TypeName.new(name: node.name, namespace: Namespace.empty)
  when Prism::ConstantPathWriteNode
    constant_as_type_name(node.target)
  end
end