Class: Prism::IndexOperatorWriteNode

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

Overview

Represents the use of an assignment operator on a call to [].

foo.bar[baz] += value
^^^^^^^^^^^^^^^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, binary_operator, binary_operator_loc, value) ⇒ IndexOperatorWriteNode

Initialize a new IndexOperatorWriteNode node.

: (Source source, Integer node_id, Location location, Integer flags, Prism::node? receiver, Location? call_operator_loc, Location opening_loc, ArgumentsNode? arguments, Location closing_loc, BlockArgumentNode? block, Symbol binary_operator, Location binary_operator_loc, Prism::node value) -> void

Parameters:



16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
# File 'lib/prism/node.rb', line 16980

def initialize(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, binary_operator, binary_operator_loc, value)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @receiver = receiver
  @call_operator_loc = call_operator_loc
  @opening_loc = opening_loc
  @arguments = arguments
  @closing_loc = closing_loc
  @block = block
  @binary_operator = binary_operator
  @binary_operator_loc = binary_operator_loc
  @value = value
end

Class Method Details

.type ⇒ :index_operator_write_node

See Node.type.

: () -> :index_operator_write_node

Returns:

  • (:index_operator_write_node)


17092
17093
17094
# File 'lib/prism/node.rb', line 17092

def self.type
  :index_operator_write_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
# File 'lib/prism/node.rb', line 17313

def ===(other) # :nodoc:
  other.is_a?(IndexOperatorWriteNode) &&
    (flags === other.flags) &&
    (receiver === other.receiver) &&
    (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (arguments === other.arguments) &&
    (closing_loc.nil? == other.closing_loc.nil?) &&
    (block === other.block) &&
    (binary_operator === other.binary_operator) &&
    (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
    (value === other.value)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


17010
17011
17012
# File 'lib/prism/node.rb', line 17010

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

#arguments ⇒ ArgumentsNode?

:call-seq:

arguments -> ArgumentsNode | nil

Returns the arguments attribute.

: () -> ArgumentsNode?

Returns:



17200
17201
17202
# File 'lib/prism/node.rb', line 17200

def arguments
  @arguments
end

#attribute_write? ⇒ Boolean

:category: Flags a call that is an attribute write, so the value being written should be returned

: () -> bool

Returns:

  • (Boolean)


17123
17124
17125
# File 'lib/prism/node.rb', line 17123

def attribute_write?
  flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
end

#binary_operator ⇒ Symbol

:call-seq:

binary_operator -> Symbol

Returns the binary_operator attribute.

: () -> Symbol

Returns:

  • (Symbol)


17242
17243
17244
# File 'lib/prism/node.rb', line 17242

def binary_operator
  @binary_operator
end

#binary_operator_loc ⇒ Location

:category: Locations :call-seq:

binary_operator_loc -> Location

Returns the Location represented by binary_operator_loc.

: () -> Location

Returns:



17253
17254
17255
17256
17257
# File 'lib/prism/node.rb', line 17253

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

#block ⇒ BlockArgumentNode?

:call-seq:

block -> BlockArgumentNode | nil

Returns the block attribute.

: () -> BlockArgumentNode?

Returns:



17232
17233
17234
# File 'lib/prism/node.rb', line 17232

def block
  @block
end

#call_operator ⇒ String?

:call-seq:

call_operator -> String | nil

Slice the location of call_operator_loc from the source.

: () -> String?

Returns:

  • (String, nil)


17286
17287
17288
# File 'lib/prism/node.rb', line 17286

def call_operator
  call_operator_loc&.slice
end

#call_operator_loc ⇒ Location?

:category: Locations :call-seq:

call_operator_loc -> Location | nil

Returns the Location represented by call_operator_loc.

: () -> Location?

Returns:



17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
# File 'lib/prism/node.rb', line 17152

def call_operator_loc
  location = @call_operator_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


17017
17018
17019
# File 'lib/prism/node.rb', line 17017

def child_nodes
  [receiver, arguments, block, value]
end

#closing ⇒ String

:call-seq:

closing -> String

Slice the location of closing_loc from the source.

: () -> String

Returns:

  • (String)


17306
17307
17308
# File 'lib/prism/node.rb', line 17306

def closing
  closing_loc.slice
end

#closing_loc ⇒ Location

:category: Locations :call-seq:

closing_loc -> Location

Returns the Location represented by closing_loc.

: () -> Location

Returns:



17211
17212
17213
17214
17215
# File 'lib/prism/node.rb', line 17211

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

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


17037
17038
17039
17040
17041
17042
17043
17044
# File 'lib/prism/node.rb', line 17037

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  if (receiver = self.receiver); compact << receiver; end
  if (arguments = self.arguments); compact << arguments; end
  if (block = self.block); compact << block; end
  compact << value
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block, binary_operator: self.binary_operator, binary_operator_loc: self.binary_operator_loc, value: self.value) ⇒ IndexOperatorWriteNode

:call-seq:

copy(**fields) -> IndexOperatorWriteNode

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

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?opening_loc: Location, ?arguments: ArgumentsNode?, ?closing_loc: Location, ?block: BlockArgumentNode?, ?binary_operator: Symbol, ?binary_operator_loc: Location, ?value: Prism::node) -> IndexOperatorWriteNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • receiver: (Prism::node, nil) (defaults to: self.receiver)
  • call_operator_loc: (Location, nil) (defaults to: self.call_operator_loc)
  • opening_loc: (Location) (defaults to: self.opening_loc)
  • arguments: (ArgumentsNode, nil) (defaults to: self.arguments)
  • closing_loc: (Location) (defaults to: self.closing_loc)
  • block: (BlockArgumentNode, nil) (defaults to: self.block)
  • binary_operator: (Symbol) (defaults to: self.binary_operator)
  • binary_operator_loc: (Location) (defaults to: self.binary_operator_loc)
  • value: (Prism::node) (defaults to: self.value)

Returns:



17052
17053
17054
# File 'lib/prism/node.rb', line 17052

def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block, binary_operator: self.binary_operator, binary_operator_loc: self.binary_operator_loc, value: self.value)
  IndexOperatorWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, binary_operator, binary_operator_loc, value)
end

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
# File 'lib/prism/node.rb', line 17059

def deconstruct_keys(keys) # :nodoc:
  (keys || i[node_id location receiver call_operator_loc opening_loc arguments closing_loc block binary_operator binary_operator_loc value call_operator opening closing]).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 :receiver                then deconstructed[:receiver] = self.receiver
    when :call_operator_loc       then deconstructed[:call_operator_loc] = self.call_operator_loc
    when :opening_loc             then deconstructed[:opening_loc] = self.opening_loc
    when :arguments               then deconstructed[:arguments] = self.arguments
    when :closing_loc             then deconstructed[:closing_loc] = self.closing_loc
    when :block                   then deconstructed[:block] = self.block
    when :binary_operator         then deconstructed[:binary_operator] = self.binary_operator
    when :binary_operator_loc     then deconstructed[:binary_operator_loc] = self.binary_operator_loc
    when :value                   then deconstructed[:value] = self.value
    when :call_operator           then deconstructed[:call_operator] = self.call_operator
    when :opening                 then deconstructed[:opening] = self.opening
    when :closing                 then deconstructed[:closing] = self.closing
    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)


17025
17026
17027
17028
17029
17030
17031
17032
# File 'lib/prism/node.rb', line 17025

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

  if (receiver = self.receiver); yield receiver; end
  if (arguments = self.arguments); yield arguments; end
  if (block = self.block); yield block; end
  yield value
end

#ignore_visibility? ⇒ Boolean

:category: Flags a call that ignores method visibility

: () -> bool

Returns:

  • (Boolean)


17131
17132
17133
# File 'lib/prism/node.rb', line 17131

def ignore_visibility?
  flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


17097
17098
17099
# File 'lib/prism/node.rb', line 17097

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

#opening ⇒ String

:call-seq:

opening -> String

Slice the location of opening_loc from the source.

: () -> String

Returns:

  • (String)


17296
17297
17298
# File 'lib/prism/node.rb', line 17296

def opening
  opening_loc.slice
end

#opening_loc ⇒ Location

:category: Locations :call-seq:

opening_loc -> Location

Returns the Location represented by opening_loc.

: () -> Location

Returns:



17179
17180
17181
17182
17183
# File 'lib/prism/node.rb', line 17179

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

#receiver ⇒ Prism::node?

:call-seq:

receiver -> Node | nil

Returns the receiver attribute.

: () -> Prism::node?

Returns:

  • (Prism::node, nil)


17141
17142
17143
# File 'lib/prism/node.rb', line 17141

def receiver
  @receiver
end

#safe_navigation? ⇒ Boolean

:category: Flags &. operator

: () -> bool

Returns:

  • (Boolean)


17107
17108
17109
# File 'lib/prism/node.rb', line 17107

def safe_navigation?
  flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
end

#save_binary_operator_loc(repository) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



17264
17265
17266
# File 'lib/prism/node.rb', line 17264

def save_binary_operator_loc(repository)
  repository.enter(node_id, :binary_operator_loc)
end

#save_call_operator_loc(repository) ⇒ Relocation::Entry?

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

: (_Repository repository) -> Relocation::Entry?

Parameters:

Returns:



17169
17170
17171
# File 'lib/prism/node.rb', line 17169

def save_call_operator_loc(repository)
  repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil?
end

#save_closing_loc(repository) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



17222
17223
17224
# File 'lib/prism/node.rb', line 17222

def save_closing_loc(repository)
  repository.enter(node_id, :closing_loc)
end

#save_opening_loc(repository) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



17190
17191
17192
# File 'lib/prism/node.rb', line 17190

def save_opening_loc(repository)
  repository.enter(node_id, :opening_loc)
end

#type ⇒ :index_operator_write_node

See Node#type.

: () -> :index_operator_write_node

Returns:

  • (:index_operator_write_node)


17085
17086
17087
# File 'lib/prism/node.rb', line 17085

def type
  :index_operator_write_node
end

#value ⇒ Prism::node

:call-seq:

value -> Node

Returns the value attribute.

: () -> Prism::node

Returns:

  • (Prism::node)


17274
17275
17276
# File 'lib/prism/node.rb', line 17274

def value
  @value
end

#variable_call? ⇒ Boolean

:category: Flags a call that could have been a local variable

: () -> bool

Returns:

  • (Boolean)


17115
17116
17117
# File 'lib/prism/node.rb', line 17115

def variable_call?
  flags.anybits?(CallNodeFlags::VARIABLE_CALL)
end