class Yard2steep::AST::ClassNode
AST::ClassNode
represents `Class` or `Module` AST
.
Constants
- KIND
Attributes
Public Class Methods
create_main()
click to toggle source
@return [AST::ClassNode]
# File lib/yard2steep/ast/class_node.rb, line 6 def self.create_main AST::ClassNode.new( kind: 'module', c_name: 'main', super_c: nil, parent: nil, ) end
new(kind:, c_name:, super_c:, parent:)
click to toggle source
@param [String] kind @param [String] c_name
@param [AST::ClassNode, nil] parent @param [String, nil] super_c
# File lib/yard2steep/ast/class_node.rb, line 24 def initialize(kind:, c_name:, super_c:, parent:) Util.assert! { KIND.include?(kind) } Util.assert! { c_name.is_a?(String) } Util.assert! { parent.is_a?(AST::ClassNode) || (parent == nil && c_name == 'main') } @kind = kind @c_name = c_name @super_c = super_c @c_list = [] # list of constants @m_list = [] # list of methods @ivar_list = [] # list of instance variables @ivarname_s = Set.new @children = [] # list of child classes @parent = parent end
Public Instance Methods
append_child(child)
click to toggle source
@param [AST::ClassNode] child @return [void]
# File lib/yard2steep/ast/class_node.rb, line 65 def append_child(child) @children.push(child) end
append_constant(c)
click to toggle source
@param [AST::ConstantNode] c @return [void]
# File lib/yard2steep/ast/class_node.rb, line 44 def append_constant(c) @c_list.push(c) end
append_ivar(ivar)
click to toggle source
@param [AST::IVarNode] ivar @return [void]
# File lib/yard2steep/ast/class_node.rb, line 56 def append_ivar(ivar) if !@ivarname_s.include?(ivar.name) @ivar_list.push(ivar) @ivarname_s << ivar.name end end
append_m(m)
click to toggle source
@param [AST::MethodNode] m @return [void]
# File lib/yard2steep/ast/class_node.rb, line 50 def append_m(m) @m_list.push(m) end
inspect()
click to toggle source
@return [String]
# File lib/yard2steep/ast/class_node.rb, line 99 def inspect <<-EOF { #{@kind}: #{c_name}, c_list: [#{@c_list.map(&:to_s).map { |s| "#{s}\n" }.join}], m_list: [#{@m_list.map(&:to_s).map { |s| "#{s}\n" }.join}], ivar_list: [#{@ivar_list.map(&:to_s).map { |s| "#{s}\n" }.join}], children: [#{@children.map(&:to_s).map { |s| "#{s}\n" }.join}], } EOF end
long_name()
click to toggle source
@return [String]
# File lib/yard2steep/ast/class_node.rb, line 70 def long_name @long_name ||= begin # NOTE: main has no long_name if @c_name == 'main' '' elsif @parent.c_name == 'main' @c_name else "#{@parent.long_name}::#{@c_name}" end end end
long_super()
click to toggle source
# File lib/yard2steep/ast/class_node.rb, line 83 def long_super @long_super ||= begin if @parent.c_name == 'main' @super_c else "#{@parent.long_name}::#{@super_c}" end end end
to_s()
click to toggle source
@return [String]
# File lib/yard2steep/ast/class_node.rb, line 94 def to_s inspect end