Class: Yard2steep::AST::ClassNode
- Inherits:
-
Object
- Object
- Yard2steep::AST::ClassNode
- Defined in:
- lib/yard2steep/ast/class_node.rb
Overview
AST::ClassNode represents ‘Class` or `Module` AST.
Constant Summary collapse
- KIND =
['class', 'module']
Instance Attribute Summary collapse
-
#c_list ⇒ Object
readonly
Returns the value of attribute c_list.
-
#c_name ⇒ Object
readonly
Returns the value of attribute c_name.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#ivar_list ⇒ Object
readonly
Returns the value of attribute ivar_list.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#m_list ⇒ Object
readonly
Returns the value of attribute m_list.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#super_c ⇒ Object
readonly
Returns the value of attribute super_c.
Class Method Summary collapse
Instance Method Summary collapse
- #append_child(child) ⇒ void
- #append_constant(c) ⇒ void
- #append_ivar(ivar) ⇒ void
- #append_m(m) ⇒ void
-
#initialize(kind:, c_name:, super_c:, parent:) ⇒ ClassNode
constructor
A new instance of ClassNode.
- #inspect ⇒ String
- #long_name ⇒ String
- #long_super ⇒ Object
- #to_s ⇒ String
Constructor Details
#initialize(kind:, c_name:, super_c:, parent:) ⇒ ClassNode
Returns a new instance of ClassNode.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |
Instance Attribute Details
#c_list ⇒ Object (readonly)
Returns the value of attribute c_list.
16 17 18 |
# File 'lib/yard2steep/ast/class_node.rb', line 16 def c_list @c_list end |
#c_name ⇒ Object (readonly)
Returns the value of attribute c_name.
16 17 18 |
# File 'lib/yard2steep/ast/class_node.rb', line 16 def c_name @c_name end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
16 17 18 |
# File 'lib/yard2steep/ast/class_node.rb', line 16 def children @children end |
#ivar_list ⇒ Object (readonly)
Returns the value of attribute ivar_list.
16 17 18 |
# File 'lib/yard2steep/ast/class_node.rb', line 16 def ivar_list @ivar_list end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
16 17 18 |
# File 'lib/yard2steep/ast/class_node.rb', line 16 def kind @kind end |
#m_list ⇒ Object (readonly)
Returns the value of attribute m_list.
16 17 18 |
# File 'lib/yard2steep/ast/class_node.rb', line 16 def m_list @m_list end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
16 17 18 |
# File 'lib/yard2steep/ast/class_node.rb', line 16 def parent @parent end |
#super_c ⇒ Object (readonly)
Returns the value of attribute super_c.
16 17 18 |
# File 'lib/yard2steep/ast/class_node.rb', line 16 def super_c @super_c end |
Class Method Details
.create_main ⇒ AST::ClassNode
6 7 8 9 10 11 12 13 |
# 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 |
Instance Method Details
#append_child(child) ⇒ void
This method returns an undefined value.
65 66 67 |
# File 'lib/yard2steep/ast/class_node.rb', line 65 def append_child(child) @children.push(child) end |
#append_constant(c) ⇒ void
This method returns an undefined value.
44 45 46 |
# File 'lib/yard2steep/ast/class_node.rb', line 44 def append_constant(c) @c_list.push(c) end |
#append_ivar(ivar) ⇒ void
This method returns an undefined value.
56 57 58 59 60 61 |
# 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) ⇒ void
This method returns an undefined value.
50 51 52 |
# File 'lib/yard2steep/ast/class_node.rb', line 50 def append_m(m) @m_list.push(m) end |
#inspect ⇒ String
99 100 101 102 103 104 105 106 107 108 109 |
# 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 ⇒ String
70 71 72 73 74 75 76 77 78 79 80 81 |
# 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 ⇒ Object
83 84 85 86 87 88 89 90 91 |
# 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 ⇒ String
94 95 96 |
# File 'lib/yard2steep/ast/class_node.rb', line 94 def to_s inspect end |