123456789_123456789_123456789_123456789_123456789_

Class: Prism::ClassNode

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PrismNode
Instance Chain:
self, PrismNode
Inherits: PrismNode
Defined in: lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents a class declaration involving the class keyword.

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(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.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3139

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

Class Method Details

.type

Return a symbol representation of this node type. See Node::type.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3254

def self.type
  :class_node
end

Instance Attribute Details

#body (readonly)

attr_reader body: Prism.node?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3218

attr_reader :body

#constant_path (readonly)

attr_reader constant_path: Prism.node

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3201

attr_reader :constant_path

#locals (readonly)

attr_reader locals: Array

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3192

attr_reader :locals

#name (readonly)

attr_reader name: Symbol

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3227

attr_reader :name

#superclass (readonly)

attr_reader superclass: Prism.node?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3216

attr_reader :superclass

Instance Method Details

#===(other)

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3260

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)

def accept: (Visitor visitor) -> void

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3155

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

#child_nodes Also known as: #deconstruct

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3160

def child_nodes
  [constant_path, superclass, body]
end

#class_keyword

def class_keyword: () -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3229

def class_keyword
  class_keyword_loc.slice
end

#class_keyword_loc

attr_reader class_keyword_loc: Location

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3194

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

def comment_targets: () -> Array[Node | Location]

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3174

def comment_targets
  [class_keyword_loc, constant_path, *inheritance_operator_loc, *superclass, *body, end_keyword_loc] #: Array[Prism::node | Location]
end

#compact_child_nodes

def compact_child_nodes: () -> Array

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3165

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)

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?constant_path: Prism.node, ?inheritance_operator_loc: Location?, ?superclass: Prism.node?, ?body: Prism.node?, ?end_keyword_loc: Location, ?name: Symbol) -> ClassNode

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3179

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

Alias for #child_nodes.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3184

alias deconstruct child_nodes

#deconstruct_keys(keys)

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, locals: Array, class_keyword_loc: Location, constant_path: Prism.node, inheritance_operator_loc: Location?, superclass: Prism.node?, body: Prism.node?, end_keyword_loc: Location, name: Symbol }

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3187

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

def end_keyword: () -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3239

def end_keyword
  end_keyword_loc.slice
end

#end_keyword_loc

attr_reader end_keyword_loc: Location

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3220

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

def inheritance_operator: () -> String?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3234

def inheritance_operator
  inheritance_operator_loc&.slice
end

#inheritance_operator_loc

attr_reader inheritance_operator_loc: Location?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3203

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

def inspect -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3244

def inspect
  InspectVisitor.compose(self)
end

#type

Return a symbol representation of this node type. See Node#type.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 3249

def type
  :class_node
end