class Prism::SingletonClassNode - Documentation for Ruby 4.0
Description: class Prism::SingletonClassNode: Represents a singleton class declaration involving the `class` keyword.
Keywords: ruby,class,Prism::SingletonClassNode

🔍

No recent searches

# class Prism::SingletonClassNode

Represents a singleton class declaration involving the `class` keyword.

    class << self end
    ^^^^^^^^^^^^^^^^^

### Attributes

body [R]

attr_reader body: `StatementsNode` | `BeginNode` | nil

expression [R]

attr_reader expression: Prism::node

locals [R]

attr_reader locals: Array

### Public Class Methods

new (source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc)
Source

    # File lib/prism/node.rb, line 17518
    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

Initialize a new `SingletonClassNode` node.

type ()
Source

    # File lib/prism/node.rb, line 17649
    def self.type
      :singleton_class_node
    end

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

### Public Instance Methods

=== (other)
Source

    # File lib/prism/node.rb, line 17655
    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

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

accept (visitor)
Source

    # File lib/prism/node.rb, line 17532
    def accept(visitor)
      visitor.visit_singleton_class_node(self)
    end

def accept: (`Visitor` visitor) -> void

child_nodes ()
Source

    # File lib/prism/node.rb, line 17537
    def child_nodes
      [expression, body]
    end

def `child_nodes`: () -> Array

Also aliased as: deconstruct
class_keyword ()
Source

    # File lib/prism/node.rb, line 17624
    def class_keyword
      class_keyword_loc.slice
    end

def `class_keyword`: () -> `String`

class_keyword_loc ()
Source

    # File lib/prism/node.rb, line 17579
    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`

comment_targets ()
Source

    # File lib/prism/node.rb, line 17558
    def comment_targets
      [class_keyword_loc, operator_loc, expression, *body, end_keyword_loc] #: Array[Prism::node | Location]
    end

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

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 17550
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      compact << expression
      compact << body if body
      compact
    end

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)
Source

    # File lib/prism/node.rb, line 17563
    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

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 ()

def deconstruct: () -> Array

Alias for: child_nodes
deconstruct_keys (keys)
Source

    # File lib/prism/node.rb, line 17571
    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

def `deconstruct_keys`: (Array keys) -> { node_id: `Integer`, location: `Location`, locals: Array, `class_keyword_loc`: `Location`, `operator_loc`: `Location`, expression: Prism::node, body: `StatementsNode` | `BeginNode` | nil, `end_keyword_loc`: `Location` }

each_child_node () { |expression| ... }
Source

    # File lib/prism/node.rb, line 17542
    def each_child_node
      return to_enum(:each_child_node) unless block_given?

      yield expression
      yield body if body
    end

def `each_child_node`: () { (Prism::node) -> void } -> void | () -> Enumerator

end_keyword ()
Source

    # File lib/prism/node.rb, line 17634
    def end_keyword
      end_keyword_loc.slice
    end

def `end_keyword`: () -> `String`

end_keyword_loc ()
Source

    # File lib/prism/node.rb, line 17611
    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`

inspect ()
Source

    # File lib/prism/node.rb, line 17639
    def inspect
      InspectVisitor.compose(self)
    end

def inspect -> `String`

operator ()
Source

    # File lib/prism/node.rb, line 17629
    def operator
      operator_loc.slice
    end

def operator: () -> `String`

operator_loc ()
Source

    # File lib/prism/node.rb, line 17592
    def operator_loc
      location = @operator_loc
      return location if location.is_a?(Location)
      @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
    end

attr_reader `operator_loc`: `Location`

save_class_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 17587
    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.

save_end_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 17619
    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.

save_operator_loc (repository)
Source

    # File lib/prism/node.rb, line 17600
    def save_operator_loc(repository)
      repository.enter(node_id, :operator_loc)
    end

Save the `operator_loc` location using the given saved source so that it can be retrieved later.

type ()
Source

    # File lib/prism/node.rb, line 17644
    def type
      :singleton_class_node
    end

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