Class: Prism::IndexOperatorWriteNode

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

Overview

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

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

Instance Attribute Summary collapse

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.



9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
# File 'lib/prism/node.rb', line 9903

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

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



10023
10024
10025
# File 'lib/prism/node.rb', line 10023

def arguments
  @arguments
end

#binary_operatorObject (readonly)

attr_reader binary_operator: Symbol



10042
10043
10044
# File 'lib/prism/node.rb', line 10042

def binary_operator
  @binary_operator
end

#blockObject (readonly)

attr_reader block: BlockArgumentNode?



10039
10040
10041
# File 'lib/prism/node.rb', line 10039

def block
  @block
end

#receiverObject (readonly)

attr_reader receiver: Prism::node?



9988
9989
9990
# File 'lib/prism/node.rb', line 9988

def receiver
  @receiver
end

#valueObject (readonly)

attr_reader value: Prism::node



10058
10059
10060
# File 'lib/prism/node.rb', line 10058

def value
  @value
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See Node::type.



10086
10087
10088
# File 'lib/prism/node.rb', line 10086

def self.type
  :index_operator_write_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
# File 'lib/prism/node.rb', line 10092

def ===(other)
  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

def accept: (Visitor visitor) -> void



9920
9921
9922
# File 'lib/prism/node.rb', line 9920

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

#attribute_write?Boolean

def attribute_write?: () -> bool

Returns:



9978
9979
9980
# File 'lib/prism/node.rb', line 9978

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

#binary_operator_locObject

attr_reader binary_operator_loc: Location



10045
10046
10047
10048
10049
# File 'lib/prism/node.rb', line 10045

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

#call_operatorObject

def call_operator: () -> String?



10061
10062
10063
# File 'lib/prism/node.rb', line 10061

def call_operator
  call_operator_loc&.slice
end

#call_operator_locObject

attr_reader call_operator_loc: Location?



9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
# File 'lib/prism/node.rb', line 9991

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_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



9925
9926
9927
# File 'lib/prism/node.rb', line 9925

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

#closingObject

def closing: () -> String



10071
10072
10073
# File 'lib/prism/node.rb', line 10071

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



10026
10027
10028
10029
10030
# File 'lib/prism/node.rb', line 10026

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

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



9950
9951
9952
# File 'lib/prism/node.rb', line 9950

def comment_targets
  [*receiver, *call_operator_loc, opening_loc, *arguments, closing_loc, *block, binary_operator_loc, value] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



9940
9941
9942
9943
9944
9945
9946
9947
# File 'lib/prism/node.rb', line 9940

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << receiver if receiver
  compact << arguments if arguments
  compact << block if block
  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) ⇒ Object

def copy: (?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



9955
9956
9957
# File 'lib/prism/node.rb', line 9955

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) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, 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 }



9963
9964
9965
# File 'lib/prism/node.rb', line 9963

def deconstruct_keys(keys)
  { node_id: node_id, location: location, 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

#each_child_node {|receiver| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



9930
9931
9932
9933
9934
9935
9936
9937
# File 'lib/prism/node.rb', line 9930

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield receiver if receiver
  yield arguments if arguments
  yield block if block
  yield value
end

#ignore_visibility?Boolean

def ignore_visibility?: () -> bool

Returns:



9983
9984
9985
# File 'lib/prism/node.rb', line 9983

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

#inspectObject

def inspect -> String



10076
10077
10078
# File 'lib/prism/node.rb', line 10076

def inspect
  InspectVisitor.compose(self)
end

#openingObject

def opening: () -> String



10066
10067
10068
# File 'lib/prism/node.rb', line 10066

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



10010
10011
10012
10013
10014
# File 'lib/prism/node.rb', line 10010

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

#operatorObject

Returns the binary operator used to modify the receiver. This method is deprecated in favor of #binary_operator.



422
423
424
425
# File 'lib/prism/node_ext.rb', line 422

def operator
  deprecated("binary_operator")
  binary_operator
end

#operator_locObject

Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of #binary_operator_loc.



429
430
431
432
# File 'lib/prism/node_ext.rb', line 429

def operator_loc
  deprecated("binary_operator_loc")
  binary_operator_loc
end

#safe_navigation?Boolean

def safe_navigation?: () -> bool

Returns:



9968
9969
9970
# File 'lib/prism/node.rb', line 9968

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

#save_binary_operator_loc(repository) ⇒ Object

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



10053
10054
10055
# File 'lib/prism/node.rb', line 10053

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

#save_call_operator_loc(repository) ⇒ Object

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



10005
10006
10007
# File 'lib/prism/node.rb', line 10005

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

#save_closing_loc(repository) ⇒ Object

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



10034
10035
10036
# File 'lib/prism/node.rb', line 10034

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

#save_opening_loc(repository) ⇒ Object

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



10018
10019
10020
# File 'lib/prism/node.rb', line 10018

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

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



10081
10082
10083
# File 'lib/prism/node.rb', line 10081

def type
  :index_operator_write_node
end

#variable_call?Boolean

def variable_call?: () -> bool

Returns:



9973
9974
9975
# File 'lib/prism/node.rb', line 9973

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