Class: Prism::ConstantTargetNode

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

Overview

Represents writing to a constant 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) ⇒ ConstantTargetNode

Initialize a new ConstantTargetNode 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)


10373
10374
10375
10376
10377
10378
10379
# File 'lib/prism/node.rb', line 10373

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 ⇒ :constant_target_node

See Node.type.

: () -> :constant_target_node

Returns:

  • (:constant_target_node)


10457
10458
10459
# File 'lib/prism/node.rb', line 10457

def self.type
  :constant_target_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


10483
10484
10485
10486
# File 'lib/prism/node.rb', line 10483

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

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


10395
10396
10397
# File 'lib/prism/node.rb', line 10395

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


10402
10403
10404
# File 'lib/prism/node.rb', line 10402

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


10418
10419
10420
# File 'lib/prism/node.rb', line 10418

def compact_child_nodes
  []
end

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

:call-seq:

copy(**fields) -> ConstantTargetNode

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

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

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:



10428
10429
10430
# File 'lib/prism/node.rb', line 10428

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
  ConstantTargetNode.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])


10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
# File 'lib/prism/node.rb', line 10435

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)


10410
10411
10412
10413
# File 'lib/prism/node.rb', line 10410

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

end

#full_name ⇒ String

Returns the full name of this constant. For example: "Foo"

: () -> String

Returns:

  • (String)


306
307
308
# File 'lib/prism/node_ext.rb', line 306

def full_name
  name.to_s
end

#full_name_parts ⇒ Array[Symbol]

Returns the list of parts for the full name of this constant. For example: [:Foo]

: () -> Array

Returns:

  • (Array[Symbol])


299
300
301
# File 'lib/prism/node_ext.rb', line 299

def full_name_parts
  [name]
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


10462
10463
10464
# File 'lib/prism/node.rb', line 10462

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

#name ⇒ Symbol

:call-seq:

name -> Symbol

Returns the name attribute.

: () -> Symbol

Returns:

  • (Symbol)


10474
10475
10476
# File 'lib/prism/node.rb', line 10474

def name
  @name
end

#type ⇒ :constant_target_node

See Node#type.

: () -> :constant_target_node

Returns:

  • (:constant_target_node)


10450
10451
10452
# File 'lib/prism/node.rb', line 10450

def type
  :constant_target_node
end