Class: YARP::ClassNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents a class declaration involving the ‘class` keyword.

class Foo end
^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, statements, end_keyword_loc, location) ⇒ ClassNode

def initialize: (locals: Array, class_keyword_loc: Location, constant_path: Node, inheritance_operator_loc: Location?, superclass: Node?, statements: Node?, end_keyword_loc: Location, location: Location) -> void



1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
# File 'lib/yarp/node.rb', line 1139

def initialize(locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, statements, end_keyword_loc, location)
  @locals = locals
  @class_keyword_loc = class_keyword_loc
  @constant_path = constant_path
  @inheritance_operator_loc = inheritance_operator_loc
  @superclass = superclass
  @statements = statements
  @end_keyword_loc = end_keyword_loc
  @location = location
end

Instance Attribute Details

#class_keyword_locObject (readonly)

attr_reader class_keyword_loc: Location



1121
1122
1123
# File 'lib/yarp/node.rb', line 1121

def class_keyword_loc
  @class_keyword_loc
end

#constant_pathObject (readonly)

attr_reader constant_path: Node



1124
1125
1126
# File 'lib/yarp/node.rb', line 1124

def constant_path
  @constant_path
end

#end_keyword_locObject (readonly)

attr_reader end_keyword_loc: Location



1136
1137
1138
# File 'lib/yarp/node.rb', line 1136

def end_keyword_loc
  @end_keyword_loc
end

#inheritance_operator_locObject (readonly)

attr_reader inheritance_operator_loc: Location?



1127
1128
1129
# File 'lib/yarp/node.rb', line 1127

def inheritance_operator_loc
  @inheritance_operator_loc
end

#localsObject (readonly)

attr_reader locals: Array



1118
1119
1120
# File 'lib/yarp/node.rb', line 1118

def locals
  @locals
end

#statementsObject (readonly)

attr_reader statements: Node?



1133
1134
1135
# File 'lib/yarp/node.rb', line 1133

def statements
  @statements
end

#superclassObject (readonly)

attr_reader superclass: Node?



1130
1131
1132
# File 'lib/yarp/node.rb', line 1130

def superclass
  @superclass
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1151
1152
1153
# File 'lib/yarp/node.rb', line 1151

def accept(visitor)
  visitor.visit_class_node(self)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



1157
1158
1159
# File 'lib/yarp/node.rb', line 1157

def child_nodes
  [constant_path, superclass, statements]
end

#class_keywordObject

def class_keyword: () -> String



1170
1171
1172
# File 'lib/yarp/node.rb', line 1170

def class_keyword
  class_keyword_loc.slice
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



1165
1166
1167
# File 'lib/yarp/node.rb', line 1165

def deconstruct_keys(keys)
  { locals: locals, class_keyword_loc: class_keyword_loc, constant_path: constant_path, inheritance_operator_loc: inheritance_operator_loc, superclass: superclass, statements: statements, end_keyword_loc: end_keyword_loc, location: location }
end

#end_keywordObject

def end_keyword: () -> String



1180
1181
1182
# File 'lib/yarp/node.rb', line 1180

def end_keyword
  end_keyword_loc.slice
end

#inheritance_operatorObject

def inheritance_operator: () -> String?



1175
1176
1177
# File 'lib/yarp/node.rb', line 1175

def inheritance_operator
  inheritance_operator_loc&.slice
end