class Prism::ClassNode
Represents a class declaration involving the class
keyword.
class Foo end ^^^^^^^^^^^^^
Attributes
attr_reader body: StatementsNode
| BeginNode
| nil
attr_reader constant_path
: ConstantReadNode
| ConstantPathNode
| CallNode
attr_reader locals: Array
attr_reader name: Symbol
attr_reader superclass: Prism::node?
Public Class Methods
Source
# File lib/prism/node.rb, line 3568 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
Initialize a new ClassNode
node.
Source
# File lib/prism/node.rb, line 3706 def self.type :class_node end
Return a symbol representation of this node type. See Node::type
.
Public Instance Methods
Source
# File lib/prism/node.rb, line 3712 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
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
Source
# File lib/prism/node.rb, line 3584 def accept(visitor) visitor.visit_class_node(self) end
def accept: (Visitor
visitor) -> void
Source
# File lib/prism/node.rb, line 3589 def child_nodes [constant_path, superclass, body] end
def child_nodes
: () -> Array[nil | Node]
Source
# File lib/prism/node.rb, line 3681 def class_keyword class_keyword_loc.slice end
def class_keyword
: () -> String
Source
# File lib/prism/node.rb, line 3624 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
attr_reader class_keyword_loc
: Location
Source
# File lib/prism/node.rb, line 3603 def comment_targets [class_keyword_loc, constant_path, *inheritance_operator_loc, *superclass, *body, end_keyword_loc] #: Array[Prism::node | Location] end
def comment_targets
: () -> Array[Node | Location]
Source
# File lib/prism/node.rb, line 3594 def compact_child_nodes compact = [] #: Array[Prism::node] compact << constant_path compact << superclass if superclass compact << body if body compact end
def compact_child_nodes
: () -> Array
Source
# File lib/prism/node.rb, line 3608 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
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
Source
# File lib/prism/node.rb, line 3616 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
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 }
Source
# File lib/prism/node.rb, line 3691 def end_keyword end_keyword_loc.slice end
def end_keyword
: () -> String
Source
# File lib/prism/node.rb, line 3665 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
attr_reader end_keyword_loc
: Location
Source
# File lib/prism/node.rb, line 3686 def inheritance_operator inheritance_operator_loc&.slice end
def inheritance_operator
: () -> String?
Source
# File lib/prism/node.rb, line 3640 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
attr_reader inheritance_operator_loc
: Location
?
Source
# File lib/prism/node.rb, line 3696 def inspect InspectVisitor.compose(self) end
def inspect -> String
Source
# File lib/prism/node.rb, line 3632 def save_class_keyword_loc(repository) repository.enter(node_id, :class_keyword_loc) end
Save the class_keyword_loc
location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 3673 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) end
Save the end_keyword_loc
location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 3654 def save_inheritance_operator_loc(repository) repository.enter(node_id, :inheritance_operator_loc) unless @inheritance_operator_loc.nil? end
Save the inheritance_operator_loc
location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 3701 def type :class_node end
Return a symbol representation of this node type. See Node#type
.