Class: Prism::CallOperatorWriteNode

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.

foo.bar += baz
^^^^^^^^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, binary_operator, binary_operator_loc, value) ⇒ CallOperatorWriteNode

Initialize a new CallOperatorWriteNode node.

: (Source source, Integer node_id, Location location, Integer flags, Prism::node? receiver, Location? call_operator_loc, Location? message_loc, Symbol read_name, Symbol write_name, Symbol binary_operator, Location binary_operator_loc, Prism::node value) -> void

Parameters:

  • source (Source)
  • node_id (Integer)
  • location (Location)
  • flags (Integer)
  • receiver (Prism::node, nil)
  • call_operator_loc (Location, nil)
  • message_loc (Location, nil)
  • read_name (Symbol)
  • write_name (Symbol)
  • binary_operator (Symbol)
  • binary_operator_loc (Location)
  • value (Prism::node)


5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
# File 'lib/prism/node.rb', line 5067

def initialize(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, binary_operator, binary_operator_loc, value)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @receiver = receiver
  @call_operator_loc = call_operator_loc
  @message_loc = message_loc
  @read_name = read_name
  @write_name = write_name
  @binary_operator = binary_operator
  @binary_operator_loc = binary_operator_loc
  @value = value
end

Class Method Details

.type ⇒ :call_operator_write_node

See Node.type.

: () -> :call_operator_write_node

Returns:

  • (:call_operator_write_node)


5172
5173
5174
# File 'lib/prism/node.rb', line 5172

def self.type
  :call_operator_write_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
# File 'lib/prism/node.rb', line 5422

def ===(other) # :nodoc:
  other.is_a?(CallOperatorWriteNode) &&
    (flags === other.flags) &&
    (receiver === other.receiver) &&
    (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
    (message_loc.nil? == other.message_loc.nil?) &&
    (read_name === other.read_name) &&
    (write_name === other.write_name) &&
    (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)


5096
5097
5098
# File 'lib/prism/node.rb', line 5096

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

#attribute_write? ⇒ Boolean

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

: () -> bool

Returns:

  • (Boolean)


5203
5204
5205
# File 'lib/prism/node.rb', line 5203

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

#binary_operator ⇒ Symbol

:call-seq:

binary_operator -> Symbol

Represents the binary operator being used.

foo.bar += value # binary_operator `:+`
        ^

Explore code sample

: () -> Symbol

Returns:

  • (Symbol)


5347
5348
5349
# File 'lib/prism/node.rb', line 5347

def binary_operator
  @binary_operator
end

#binary_operator_loc ⇒ Location

:category: Locations :call-seq:

binary_operator_loc -> Location

Represents the Location of the binary operator.

foo.bar += value
        ^^

Explore code sample

: () -> Location

Returns:



5365
5366
5367
5368
5369
# File 'lib/prism/node.rb', line 5365

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_operator ⇒ String?

:call-seq:

call_operator -> String | nil

Slice the location of call_operator_loc from the source.

: () -> String?

Returns:

  • (String, nil)


5405
5406
5407
# File 'lib/prism/node.rb', line 5405

def call_operator
  call_operator_loc&.slice
end

#call_operator_loc ⇒ Location?

:category: Locations :call-seq:

call_operator_loc -> Location | nil

Represents the Location of the call operator.

foo.bar += value
   ^

Explore code sample

: () -> Location?

Returns:



5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
# File 'lib/prism/node.rb', line 5246

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?])


5103
5104
5105
# File 'lib/prism/node.rb', line 5103

def child_nodes
  [receiver, value]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


5121
5122
5123
5124
5125
5126
# File 'lib/prism/node.rb', line 5121

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  if (receiver = self.receiver); compact << receiver; 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, message_loc: self.message_loc, read_name: self.read_name, write_name: self.write_name, binary_operator: self.binary_operator, binary_operator_loc: self.binary_operator_loc, value: self.value) ⇒ CallOperatorWriteNode

:call-seq:

copy(**fields) -> CallOperatorWriteNode

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?, ?message_loc: Location?, ?read_name: Symbol, ?write_name: Symbol, ?binary_operator: Symbol, ?binary_operator_loc: Location, ?value: Prism::node) -> CallOperatorWriteNode

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)
  • message_loc: (Location, nil) (defaults to: self.message_loc)
  • read_name: (Symbol) (defaults to: self.read_name)
  • write_name: (Symbol) (defaults to: self.write_name)
  • 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:



5134
5135
5136
# File 'lib/prism/node.rb', line 5134

def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, message_loc: self.message_loc, read_name: self.read_name, write_name: self.write_name, binary_operator: self.binary_operator, binary_operator_loc: self.binary_operator_loc, value: self.value)
  CallOperatorWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, 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])


5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
# File 'lib/prism/node.rb', line 5141

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location receiver call_operator_loc message_loc read_name write_name binary_operator binary_operator_loc value call_operator message]).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 :message_loc             then deconstructed[:message_loc] = self.message_loc
    when :read_name               then deconstructed[:read_name] = self.read_name
    when :write_name              then deconstructed[:write_name] = self.write_name
    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 :message                 then deconstructed[:message] = self.message
    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)


5111
5112
5113
5114
5115
5116
# File 'lib/prism/node.rb', line 5111

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

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

#ignore_visibility? ⇒ Boolean

:category: Flags a call that ignores method visibility

: () -> bool

Returns:

  • (Boolean)


5211
5212
5213
# File 'lib/prism/node.rb', line 5211

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

#inspect ⇒ String

: () -> String

Returns:

  • (String)


5177
5178
5179
# File 'lib/prism/node.rb', line 5177

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

#message ⇒ String?

:call-seq:

message -> String | nil

Slice the location of message_loc from the source.

: () -> String?

Returns:

  • (String, nil)


5415
5416
5417
# File 'lib/prism/node.rb', line 5415

def message
  message_loc&.slice
end

#message_loc ⇒ Location?

:category: Locations :call-seq:

message_loc -> Location | nil

Represents the Location of the message.

foo.bar += value
    ^^^

Explore code sample

: () -> Location?

Returns:



5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
# File 'lib/prism/node.rb', line 5280

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

#read_name ⇒ Symbol

:call-seq:

read_name -> Symbol

Represents the name of the method being called.

foo.bar += value # read_name `:bar`
    ^^^

Explore code sample

: () -> Symbol

Returns:

  • (Symbol)


5313
5314
5315
# File 'lib/prism/node.rb', line 5313

def read_name
  @read_name
end

#receiver ⇒ Prism::node?

:call-seq:

receiver -> Node | nil

The object that the method is being called on. This can be either nil or any non-void expressions.

foo.bar += value
^^^

Explore code sample

: () -> Prism::node?

Returns:

  • (Prism::node, nil)


5228
5229
5230
# File 'lib/prism/node.rb', line 5228

def receiver
  @receiver
end

#safe_navigation? ⇒ Boolean

:category: Flags &. operator

: () -> bool

Returns:

  • (Boolean)


5187
5188
5189
# File 'lib/prism/node.rb', line 5187

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:



5376
5377
5378
# File 'lib/prism/node.rb', line 5376

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:



5263
5264
5265
# File 'lib/prism/node.rb', line 5263

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

#save_message_loc(repository) ⇒ Relocation::Entry?

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

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

Parameters:

Returns:



5297
5298
5299
# File 'lib/prism/node.rb', line 5297

def save_message_loc(repository)
  repository.enter(node_id, :message_loc) unless @message_loc.nil?
end

#type ⇒ :call_operator_write_node

See Node#type.

: () -> :call_operator_write_node

Returns:

  • (:call_operator_write_node)


5165
5166
5167
# File 'lib/prism/node.rb', line 5165

def type
  :call_operator_write_node
end

#value ⇒ Prism::node

:call-seq:

value -> Node

Represents the value being assigned.

foo.bar += value
           ^^^^^

Explore code sample

: () -> Prism::node

Returns:

  • (Prism::node)


5393
5394
5395
# File 'lib/prism/node.rb', line 5393

def value
  @value
end

#variable_call? ⇒ Boolean

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

: () -> bool

Returns:

  • (Boolean)


5195
5196
5197
# File 'lib/prism/node.rb', line 5195

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

#write_name ⇒ Symbol

:call-seq:

write_name -> Symbol

Represents the name of the method being written to.

foo.bar += value # write_name `:bar=`
    ^^^

Explore code sample

: () -> Symbol

Returns:

  • (Symbol)


5330
5331
5332
# File 'lib/prism/node.rb', line 5330

def write_name
  @write_name
end