Class: Prism::CallAndWriteNode

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 the &&= operator on a call.

foo.bar &&= value
^^^^^^^^^^^^^^^^^

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, operator_loc, value) ⇒ CallAndWriteNode

Initialize a new CallAndWriteNode 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, Location 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)
  • operator_loc (Location)
  • value (Prism::node)


4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
# File 'lib/prism/node.rb', line 4174

def initialize(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, 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
  @operator_loc = operator_loc
  @value = value
end

Class Method Details

.type ⇒ :call_and_write_node

See Node.type.

: () -> :call_and_write_node

Returns:

  • (:call_and_write_node)


4278
4279
4280
# File 'lib/prism/node.rb', line 4278

def self.type
  :call_and_write_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
# File 'lib/prism/node.rb', line 4521

def ===(other) # :nodoc:
  other.is_a?(CallAndWriteNode) &&
    (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) &&
    (operator_loc.nil? == other.operator_loc.nil?) &&
    (value === other.value)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


4202
4203
4204
# File 'lib/prism/node.rb', line 4202

def accept(visitor)
  visitor.visit_call_and_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)


4309
4310
4311
# File 'lib/prism/node.rb', line 4309

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

#call_operator ⇒ String?

:call-seq:

call_operator -> String | nil

Slice the location of call_operator_loc from the source.

: () -> String?

Returns:

  • (String, nil)


4494
4495
4496
# File 'lib/prism/node.rb', line 4494

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:



4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
# File 'lib/prism/node.rb', line 4352

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


4209
4210
4211
# File 'lib/prism/node.rb', line 4209

def child_nodes
  [receiver, value]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


4227
4228
4229
4230
4231
4232
# File 'lib/prism/node.rb', line 4227

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, operator_loc: self.operator_loc, value: self.value) ⇒ CallAndWriteNode

:call-seq:

copy(**fields) -> CallAndWriteNode

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, ?operator_loc: Location, ?value: Prism::node) -> CallAndWriteNode

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

Returns:



4240
4241
4242
# File 'lib/prism/node.rb', line 4240

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, operator_loc: self.operator_loc, value: self.value)
  CallAndWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, operator_loc, value)
end

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
# File 'lib/prism/node.rb', line 4247

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


4217
4218
4219
4220
4221
4222
# File 'lib/prism/node.rb', line 4217

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)


4317
4318
4319
# File 'lib/prism/node.rb', line 4317

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

#inspect ⇒ String

: () -> String

Returns:

  • (String)


4283
4284
4285
# File 'lib/prism/node.rb', line 4283

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)


4504
4505
4506
# File 'lib/prism/node.rb', line 4504

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:



4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
# File 'lib/prism/node.rb', line 4386

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

#operator ⇒ String

:call-seq:

operator -> String

Slice the location of operator_loc from the source.

: () -> String

Returns:

  • (String)


4514
4515
4516
# File 'lib/prism/node.rb', line 4514

def operator
  operator_loc.slice
end

#operator_loc ⇒ Location

:category: Locations :call-seq:

operator_loc -> Location

Represents the Location of the operator.

foo.bar &&= value
        ^^^

Explore code sample

: () -> Location

Returns:



4454
4455
4456
4457
4458
# File 'lib/prism/node.rb', line 4454

def operator_loc
  location = @operator_loc
  return location if location.is_a?(Location)
  @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
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)


4419
4420
4421
# File 'lib/prism/node.rb', line 4419

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 expression.

foo.bar &&= value
^^^

Explore code sample

: () -> Prism::node?

Returns:

  • (Prism::node, nil)


4334
4335
4336
# File 'lib/prism/node.rb', line 4334

def receiver
  @receiver
end

#safe_navigation? ⇒ Boolean

:category: Flags &. operator

: () -> bool

Returns:

  • (Boolean)


4293
4294
4295
# File 'lib/prism/node.rb', line 4293

def safe_navigation?
  flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
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:



4369
4370
4371
# File 'lib/prism/node.rb', line 4369

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:



4403
4404
4405
# File 'lib/prism/node.rb', line 4403

def save_message_loc(repository)
  repository.enter(node_id, :message_loc) unless @message_loc.nil?
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:



4465
4466
4467
# File 'lib/prism/node.rb', line 4465

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

#type ⇒ :call_and_write_node

See Node#type.

: () -> :call_and_write_node

Returns:

  • (:call_and_write_node)


4271
4272
4273
# File 'lib/prism/node.rb', line 4271

def type
  :call_and_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)


4482
4483
4484
# File 'lib/prism/node.rb', line 4482

def value
  @value
end

#variable_call? ⇒ Boolean

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

: () -> bool

Returns:

  • (Boolean)


4301
4302
4303
# File 'lib/prism/node.rb', line 4301

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)


4436
4437
4438
# File 'lib/prism/node.rb', line 4436

def write_name
  @write_name
end