Class: RBI::ConstBuilder

Inherits:
ASTVisitor show all
Extended by:
T::Sig
Defined in:
lib/rbi/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ASTVisitor

#visit_all

Constructor Details

#initializeConstBuilder



369
370
371
372
# File 'lib/rbi/parser.rb', line 369

def initialize
  super
  @names = T.let([], T::Array[String])
end

Instance Attribute Details

#namesObject

Returns the value of attribute names.



366
367
368
# File 'lib/rbi/parser.rb', line 366

def names
  @names
end

Class Method Details

.visit(node) ⇒ Object



358
359
360
361
362
363
# File 'lib/rbi/parser.rb', line 358

def self.visit(node)
  v = ConstBuilder.new
  v.visit(node)
  return nil if v.names.empty?
  v.names.join("::")
end

Instance Method Details

#visit(node) ⇒ Object



375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/rbi/parser.rb', line 375

def visit(node)
  return unless node
  case node.type
  when :const, :casgn
    visit(node.children[0])
    @names << node.children[1].to_s
  when :cbase
    @names << ""
  when :sym
    @names << ":#{node.children[0]}"
  end
end