Class: Prism::InstanceVariableWriteNode

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

Overview

Represents writing to an instance variable.

^^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name, name_loc, value, operator_loc) ⇒ InstanceVariableWriteNode

Initialize a new InstanceVariableWriteNode node.

: (Source source, Integer node_id, Location location, Integer flags, Symbol name, Location name_loc, Prism::node value, Location operator_loc) -> void

Parameters:



18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
# File 'lib/prism/node.rb', line 18887

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

Class Method Details

.type ⇒ :instance_variable_write_node

See Node.type.

: () -> :instance_variable_write_node

Returns:

  • (:instance_variable_write_node)


18979
18980
18981
# File 'lib/prism/node.rb', line 18979

def self.type
  :instance_variable_write_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


19101
19102
19103
19104
19105
19106
19107
# File 'lib/prism/node.rb', line 19101

def ===(other) # :nodoc:
  other.is_a?(InstanceVariableWriteNode) &&
    (name === other.name) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (value === other.value) &&
    (operator_loc.nil? == other.operator_loc.nil?)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


18912
18913
18914
# File 'lib/prism/node.rb', line 18912

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


18919
18920
18921
# File 'lib/prism/node.rb', line 18919

def child_nodes
  [value]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


18936
18937
18938
# File 'lib/prism/node.rb', line 18936

def compact_child_nodes
  [value]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, value: self.value, operator_loc: self.operator_loc) ⇒ InstanceVariableWriteNode

:call-seq:

copy(**fields) -> InstanceVariableWriteNode

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

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?value: Prism::node, ?operator_loc: Location) -> InstanceVariableWriteNode

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)
  • name_loc: (Location) (defaults to: self.name_loc)
  • value: (Prism::node) (defaults to: self.value)
  • operator_loc: (Location) (defaults to: self.operator_loc)

Returns:



18946
18947
18948
# File 'lib/prism/node.rb', line 18946

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, value: self.value, operator_loc: self.operator_loc)
  InstanceVariableWriteNode.new(source, node_id, location, flags, name, name_loc, value, operator_loc)
end

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
# File 'lib/prism/node.rb', line 18953

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


18927
18928
18929
18930
18931
# File 'lib/prism/node.rb', line 18927

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

  yield value
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


18984
18985
18986
# File 'lib/prism/node.rb', line 18984

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

#name ⇒ Symbol

:call-seq:

name -> Symbol

The name of the instance variable, which is a @ followed by an identifier.

</code>

Explore code sample

: () -> Symbol

Returns:

  • (Symbol)


19004
19005
19006
# File 'lib/prism/node.rb', line 19004

def name
  @name
end

#name_loc ⇒ Location

:category: Locations :call-seq:

name_loc -> Location

The Location of the variable name.

^^^

Explore code sample

: () -> Location

Returns:



19022
19023
19024
19025
19026
# File 'lib/prism/node.rb', line 19022

def name_loc
  location = @name_loc
  return location if location.is_a?(Location)
  @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#newline_flag!(lines) ⇒ void

This method returns an undefined value.

: (Array lines) -> void

Parameters:

  • lines (Array[bool])


305
306
307
# File 'lib/prism/parse_result/newlines.rb', line 305

def newline_flag!(lines) # :nodoc:
  value.newline_flag!(lines)
end

#operator ⇒ String

:call-seq:

operator -> String

Slice the location of operator_loc from the source.

: () -> String

Returns:

  • (String)


19094
19095
19096
# File 'lib/prism/node.rb', line 19094

def operator
  operator_loc.slice
end

#operator_loc ⇒ Location

:category: Locations :call-seq:

operator_loc -> Location

The Location of the = operator.

</code>

Explore code sample

: () -> Location

Returns:



19071
19072
19073
19074
19075
# File 'lib/prism/node.rb', line 19071

def operator_loc
  location = @operator_loc
  return location if location.is_a?(Location)
  @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#save_name_loc(repository) ⇒ Relocation::Entry

:category: Repository Save the name_loc location using the given saved source so that it can be retrieved later.

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



19033
19034
19035
# File 'lib/prism/node.rb', line 19033

def save_name_loc(repository)
  repository.enter(node_id, :name_loc)
end

#save_operator_loc(repository) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



19082
19083
19084
# File 'lib/prism/node.rb', line 19082

def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc)
end

#type ⇒ :instance_variable_write_node

See Node#type.

: () -> :instance_variable_write_node

Returns:

  • (:instance_variable_write_node)


18972
18973
18974
# File 'lib/prism/node.rb', line 18972

def type
  :instance_variable_write_node
end

#value ⇒ Prism::node

:call-seq:

value -> Node

The value to write to the instance variable. It can be any non-void expression.

</code>

Explore code sample

: () -> Prism::node

Returns:

  • (Prism::node)


19053
19054
19055
# File 'lib/prism/node.rb', line 19053

def value
  @value
end