Class: Prism::ClassNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ClassNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a class declaration involving the ‘class` keyword.
class Foo end
^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: StatementsNode | BeginNode | nil.
-
#constant_path ⇒ Object
readonly
attr_reader constant_path: ConstantReadNode | ConstantPathNode | CallNode.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#name ⇒ Object
readonly
attr_reader name: Symbol.
-
#superclass ⇒ Object
readonly
attr_reader superclass: Prism::node?.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#class_keyword ⇒ Object
def class_keyword: () -> String.
-
#class_keyword_loc ⇒ Object
attr_reader class_keyword_loc: Location.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, constant_path: self.constant_path, inheritance_operator_loc: self.inheritance_operator_loc, superclass: self.superclass, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?constant_path: ConstantReadNode | ConstantPathNode | CallNode, ?inheritance_operator_loc: Location?, ?superclass: Prism::node?, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location, ?name: Symbol) -> ClassNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, locals: Array, class_keyword_loc: Location, constant_path: ConstantReadNode | ConstantPathNode | CallNode, inheritance_operator_loc: Location?, superclass: Prism::node?, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location, name: Symbol }.
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location.
-
#inheritance_operator ⇒ Object
def inheritance_operator: () -> String?.
-
#inheritance_operator_loc ⇒ Object
attr_reader inheritance_operator_loc: Location?.
-
#initialize(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name) ⇒ ClassNode
constructor
Initialize a new ClassNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name) ⇒ ClassNode
Initialize a new ClassNode node.
3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 |
# File 'lib/prism/node.rb', line 3239 def initialize(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name) @source = source @node_id = node_id @location = location @flags = flags @locals = locals @class_keyword_loc = class_keyword_loc @constant_path = constant_path @inheritance_operator_loc = inheritance_operator_loc @superclass = superclass @body = body @end_keyword_loc = end_keyword_loc @name = name end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: StatementsNode | BeginNode | nil
3321 3322 3323 |
# File 'lib/prism/node.rb', line 3321 def body @body end |
#constant_path ⇒ Object (readonly)
attr_reader constant_path: ConstantReadNode | ConstantPathNode | CallNode
3302 3303 3304 |
# File 'lib/prism/node.rb', line 3302 def constant_path @constant_path end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
3292 3293 3294 |
# File 'lib/prism/node.rb', line 3292 def locals @locals end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
3331 3332 3333 |
# File 'lib/prism/node.rb', line 3331 def name @name end |
#superclass ⇒ Object (readonly)
attr_reader superclass: Prism::node?
3318 3319 3320 |
# File 'lib/prism/node.rb', line 3318 def superclass @superclass end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
3359 3360 3361 |
# File 'lib/prism/node.rb', line 3359 def self.type :class_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 |
# File 'lib/prism/node.rb', line 3365 def ===(other) other.is_a?(ClassNode) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (class_keyword_loc.nil? == other.class_keyword_loc.nil?) && (constant_path === other.constant_path) && (inheritance_operator_loc.nil? == other.inheritance_operator_loc.nil?) && (superclass === other.superclass) && (body === other.body) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) && (name === other.name) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
3255 3256 3257 |
# File 'lib/prism/node.rb', line 3255 def accept(visitor) visitor.visit_class_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
3260 3261 3262 |
# File 'lib/prism/node.rb', line 3260 def child_nodes [constant_path, superclass, body] end |
#class_keyword ⇒ Object
def class_keyword: () -> String
3334 3335 3336 |
# File 'lib/prism/node.rb', line 3334 def class_keyword class_keyword_loc.slice end |
#class_keyword_loc ⇒ Object
attr_reader class_keyword_loc: Location
3295 3296 3297 3298 3299 |
# File 'lib/prism/node.rb', line 3295 def class_keyword_loc location = @class_keyword_loc return location if location.is_a?(Location) @class_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
3274 3275 3276 |
# File 'lib/prism/node.rb', line 3274 def comment_targets [class_keyword_loc, constant_path, *inheritance_operator_loc, *superclass, *body, end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
3265 3266 3267 3268 3269 3270 3271 |
# File 'lib/prism/node.rb', line 3265 def compact_child_nodes compact = [] #: Array[Prism::node] compact << constant_path compact << superclass if superclass compact << body if body compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, constant_path: self.constant_path, inheritance_operator_loc: self.inheritance_operator_loc, superclass: self.superclass, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?constant_path: ConstantReadNode | ConstantPathNode | CallNode, ?inheritance_operator_loc: Location?, ?superclass: Prism::node?, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location, ?name: Symbol) -> ClassNode
3279 3280 3281 |
# File 'lib/prism/node.rb', line 3279 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, constant_path: self.constant_path, inheritance_operator_loc: self.inheritance_operator_loc, superclass: self.superclass, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name) ClassNode.new(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, locals: Array, class_keyword_loc: Location, constant_path: ConstantReadNode | ConstantPathNode | CallNode, inheritance_operator_loc: Location?, superclass: Prism::node?, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location, name: Symbol }
3287 3288 3289 |
# File 'lib/prism/node.rb', line 3287 def deconstruct_keys(keys) { node_id: node_id, location: location, locals: locals, class_keyword_loc: class_keyword_loc, constant_path: constant_path, inheritance_operator_loc: inheritance_operator_loc, superclass: superclass, body: body, end_keyword_loc: end_keyword_loc, name: name } end |
#end_keyword ⇒ Object
def end_keyword: () -> String
3344 3345 3346 |
# File 'lib/prism/node.rb', line 3344 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location
3324 3325 3326 3327 3328 |
# File 'lib/prism/node.rb', line 3324 def end_keyword_loc location = @end_keyword_loc return location if location.is_a?(Location) @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#inheritance_operator ⇒ Object
def inheritance_operator: () -> String?
3339 3340 3341 |
# File 'lib/prism/node.rb', line 3339 def inheritance_operator inheritance_operator_loc&.slice end |
#inheritance_operator_loc ⇒ Object
attr_reader inheritance_operator_loc: Location?
3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 |
# File 'lib/prism/node.rb', line 3305 def inheritance_operator_loc location = @inheritance_operator_loc case location when nil nil when Location location else @inheritance_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#inspect ⇒ Object
def inspect -> String
3349 3350 3351 |
# File 'lib/prism/node.rb', line 3349 def inspect InspectVisitor.compose(self) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
3354 3355 3356 |
# File 'lib/prism/node.rb', line 3354 def type :class_node end |