Class: Prism::ClassVariableTargetNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c

Overview

Represents writing to a class variable in a context that doesn't have an explicit value.

@@foo, @@bar = baz
^^^^^  ^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name) ⇒ ClassVariableTargetNode

Initialize a new ClassVariableTargetNode node.

: (Source source, Integer node_id, Location location, Integer flags, Symbol name) -> void

Parameters:

  • source (Source)
  • node_id (Integer)
  • location (Location)
  • flags (Integer)
  • name (Symbol)


8020
8021
8022
8023
8024
8025
8026
# File 'lib/prism/node.rb', line 8020

def initialize(source, node_id, location, flags, name)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @name = name
end

Class Method Details

.type ⇒ :class_variable_target_node

See Node.type.

: () -> :class_variable_target_node

Returns:

  • (:class_variable_target_node)


8104
8105
8106
# File 'lib/prism/node.rb', line 8104

def self.type
  :class_variable_target_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


8130
8131
8132
8133
# File 'lib/prism/node.rb', line 8130

def ===(other) # :nodoc:
  other.is_a?(ClassVariableTargetNode) &&
    (name === other.name)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


8042
8043
8044
# File 'lib/prism/node.rb', line 8042

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

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


8049
8050
8051
# File 'lib/prism/node.rb', line 8049

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


8065
8066
8067
# File 'lib/prism/node.rb', line 8065

def compact_child_nodes
  []
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name) ⇒ ClassVariableTargetNode

:call-seq:

copy(**fields) -> ClassVariableTargetNode

Creates a copy of self with the given fields, using self as the template.

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> ClassVariableTargetNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • name: (Symbol) (defaults to: self.name)

Returns:



8075
8076
8077
# File 'lib/prism/node.rb', line 8075

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
  ClassVariableTargetNode.new(source, node_id, location, flags, name)
end

#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
# File 'lib/prism/node.rb', line 8082

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location name]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :name                    then deconstructed[:name] = self.name
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


8057
8058
8059
8060
# File 'lib/prism/node.rb', line 8057

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


8109
8110
8111
# File 'lib/prism/node.rb', line 8109

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#name ⇒ Symbol

:call-seq:

name -> Symbol

Returns the name attribute.

: () -> Symbol

Returns:

  • (Symbol)


8121
8122
8123
# File 'lib/prism/node.rb', line 8121

def name
  @name
end

#type ⇒ :class_variable_target_node

See Node#type.

: () -> :class_variable_target_node

Returns:

  • (:class_variable_target_node)


8097
8098
8099
# File 'lib/prism/node.rb', line 8097

def type
  :class_variable_target_node
end