Class: Prism::SingletonClassNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::SingletonClassNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a singleton class declaration involving the ‘class` keyword.
class << self end
^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: StatementsNode | BeginNode | nil.
-
#expression ⇒ Object
readonly
attr_reader expression: Prism::node.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
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, operator_loc: self.operator_loc, expression: self.expression, body: self.body, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?operator_loc: Location, ?expression: Prism::node, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location) -> SingletonClassNode.
- #deconstruct_keys(keys) ⇒ Object
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location.
-
#initialize(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc) ⇒ SingletonClassNode
constructor
Initialize a new SingletonClassNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location.
-
#save_class_keyword_loc(repository) ⇒ Object
Save the class_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_end_keyword_loc(repository) ⇒ Object
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc) ⇒ SingletonClassNode
Initialize a new SingletonClassNode node.
16294 16295 16296 16297 16298 16299 16300 16301 16302 16303 16304 16305 |
# File 'lib/prism/node.rb', line 16294 def initialize(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @locals = locals @class_keyword_loc = class_keyword_loc @operator_loc = operator_loc @expression = expression @body = body @end_keyword_loc = end_keyword_loc end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: StatementsNode | BeginNode | nil
16376 16377 16378 |
# File 'lib/prism/node.rb', line 16376 def body @body end |
#expression ⇒ Object (readonly)
attr_reader expression: Prism::node
16373 16374 16375 |
# File 'lib/prism/node.rb', line 16373 def expression @expression end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
16344 16345 16346 |
# File 'lib/prism/node.rb', line 16344 def locals @locals end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
16417 16418 16419 |
# File 'lib/prism/node.rb', line 16417 def self.type :singleton_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.
16423 16424 16425 16426 16427 16428 16429 16430 16431 16432 |
# File 'lib/prism/node.rb', line 16423 def ===(other) other.is_a?(SingletonClassNode) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (class_keyword_loc.nil? == other.class_keyword_loc.nil?) && (operator_loc.nil? == other.operator_loc.nil?) && (expression === other.expression) && (body === other.body) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
16308 16309 16310 |
# File 'lib/prism/node.rb', line 16308 def accept(visitor) visitor.visit_singleton_class_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
16313 16314 16315 |
# File 'lib/prism/node.rb', line 16313 def child_nodes [expression, body] end |
#class_keyword ⇒ Object
def class_keyword: () -> String
16392 16393 16394 |
# File 'lib/prism/node.rb', line 16392 def class_keyword class_keyword_loc.slice end |
#class_keyword_loc ⇒ Object
attr_reader class_keyword_loc: Location
16347 16348 16349 16350 16351 |
# File 'lib/prism/node.rb', line 16347 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]
16326 16327 16328 |
# File 'lib/prism/node.rb', line 16326 def comment_targets [class_keyword_loc, operator_loc, expression, *body, end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
16318 16319 16320 16321 16322 16323 |
# File 'lib/prism/node.rb', line 16318 def compact_child_nodes compact = [] #: Array[Prism::node] compact << expression 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, operator_loc: self.operator_loc, expression: self.expression, body: self.body, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?operator_loc: Location, ?expression: Prism::node, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location) -> SingletonClassNode
16331 16332 16333 |
# File 'lib/prism/node.rb', line 16331 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, operator_loc: self.operator_loc, expression: self.expression, body: self.body, end_keyword_loc: self.end_keyword_loc) SingletonClassNode.new(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc) end |
#deconstruct_keys(keys) ⇒ Object
16339 16340 16341 |
# File 'lib/prism/node.rb', line 16339 def deconstruct_keys(keys) { node_id: node_id, location: location, locals: locals, class_keyword_loc: class_keyword_loc, operator_loc: operator_loc, expression: expression, body: body, end_keyword_loc: end_keyword_loc } end |
#end_keyword ⇒ Object
def end_keyword: () -> String
16402 16403 16404 |
# File 'lib/prism/node.rb', line 16402 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location
16379 16380 16381 16382 16383 |
# File 'lib/prism/node.rb', line 16379 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 |
#inspect ⇒ Object
def inspect -> String
16407 16408 16409 |
# File 'lib/prism/node.rb', line 16407 def inspect InspectVisitor.compose(self) end |
#operator ⇒ Object
def operator: () -> String
16397 16398 16399 |
# File 'lib/prism/node.rb', line 16397 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
16360 16361 16362 16363 16364 |
# File 'lib/prism/node.rb', line 16360 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#save_class_keyword_loc(repository) ⇒ Object
Save the class_keyword_loc location using the given saved source so that it can be retrieved later.
16355 16356 16357 |
# File 'lib/prism/node.rb', line 16355 def save_class_keyword_loc(repository) repository.enter(node_id, :class_keyword_loc) end |
#save_end_keyword_loc(repository) ⇒ Object
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
16387 16388 16389 |
# File 'lib/prism/node.rb', line 16387 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) end |
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
16368 16369 16370 |
# File 'lib/prism/node.rb', line 16368 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
16412 16413 16414 |
# File 'lib/prism/node.rb', line 16412 def type :singleton_class_node end |