Class: Prism::LocalVariableTargetNode

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 local variable in a context that doesn't have an explicit value.

foo, bar = baz
^^^  ^^^

foo => baz
       ^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name, depth) ⇒ LocalVariableTargetNode

Initialize a new LocalVariableTargetNode node.

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

Parameters:

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


22231
22232
22233
22234
22235
22236
22237
22238
# File 'lib/prism/node.rb', line 22231

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

Class Method Details

.type ⇒ :local_variable_target_node

See Node.type.

: () -> :local_variable_target_node

Returns:

  • (:local_variable_target_node)


22317
22318
22319
# File 'lib/prism/node.rb', line 22317

def self.type
  :local_variable_target_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


22353
22354
22355
22356
22357
# File 'lib/prism/node.rb', line 22353

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

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


22254
22255
22256
# File 'lib/prism/node.rb', line 22254

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


22261
22262
22263
# File 'lib/prism/node.rb', line 22261

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


22277
22278
22279
# File 'lib/prism/node.rb', line 22277

def compact_child_nodes
  []
end

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

:call-seq:

copy(**fields) -> LocalVariableTargetNode

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

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

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)
  • depth: (Integer) (defaults to: self.depth)

Returns:



22287
22288
22289
# File 'lib/prism/node.rb', line 22287

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

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
# File 'lib/prism/node.rb', line 22294

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location name depth]).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
    when :depth                   then deconstructed[:depth] = self.depth
    end
  end
end

#depth ⇒ Integer

:call-seq:

depth -> Integer

Returns the depth attribute.

: () -> Integer

Returns:

  • (Integer)


22344
22345
22346
# File 'lib/prism/node.rb', line 22344

def depth
  @depth
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)


22269
22270
22271
22272
# File 'lib/prism/node.rb', line 22269

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

end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


22322
22323
22324
# File 'lib/prism/node.rb', line 22322

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

#name ⇒ Symbol

:call-seq:

name -> Symbol

Returns the name attribute.

: () -> Symbol

Returns:

  • (Symbol)


22334
22335
22336
# File 'lib/prism/node.rb', line 22334

def name
  @name
end

#type ⇒ :local_variable_target_node

See Node#type.

: () -> :local_variable_target_node

Returns:

  • (:local_variable_target_node)


22310
22311
22312
# File 'lib/prism/node.rb', line 22310

def type
  :local_variable_target_node
end