Class: Prism::CallAndWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::CallAndWriteNode
- 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
^^^^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :call_and_write_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#attribute_write? ⇒ Boolean
:category: Flags a call that is an attribute write, so the value being written should be returned.
-
#call_operator ⇒ String?
:call-seq: call_operator -> String | nil.
-
#call_operator_loc ⇒ Location?
:category: Locations :call-seq: call_operator_loc -> Location | nil.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#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.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#ignore_visibility? ⇒ Boolean
:category: Flags a call that ignores method visibility.
-
#initialize(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, operator_loc, value) ⇒ CallAndWriteNode
constructor
Initialize a new CallAndWriteNode node.
-
#inspect ⇒ String
: () -> String.
-
#message ⇒ String?
:call-seq: message -> String | nil.
-
#message_loc ⇒ Location?
:category: Locations :call-seq: message_loc -> Location | nil.
-
#operator ⇒ String
:call-seq: operator -> String.
-
#operator_loc ⇒ Location
:category: Locations :call-seq: operator_loc -> Location.
-
#read_name ⇒ Symbol
:call-seq: read_name -> Symbol.
-
#receiver ⇒ Prism::node?
:call-seq: receiver -> Node | nil.
-
#safe_navigation? ⇒ Boolean
:category: Flags &.
-
#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.
-
#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.
-
#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.
-
#type ⇒ :call_and_write_node
See
Node#type. -
#value ⇒ Prism::node
:call-seq: value -> Node.
-
#variable_call? ⇒ Boolean
:category: Flags a call that could have been a local variable.
-
#write_name ⇒ Symbol
:call-seq: write_name -> Symbol.
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
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, , 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 = @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
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
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?) && (.nil? == other..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
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
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?
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
^
: () -> Location?
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
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
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
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., 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, , read_name, write_name, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> 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 read_name write_name operator_loc value call_operator 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. 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. 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
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
4317 4318 4319 |
# File 'lib/prism/node.rb', line 4317 def ignore_visibility? flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY) end |
#inspect ⇒ String
: () -> 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?
4504 4505 4506 |
# File 'lib/prism/node.rb', line 4504 def &.slice end |
#message_loc ⇒ Location?
:category: Locations :call-seq:
message_loc -> Location | nil
Represents the Location of the message.
foo.bar &&= value
^^^
: () -> Location?
4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 |
# File 'lib/prism/node.rb', line 4386 def location = case location when nil nil when Location location else = 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
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
^^^
: () -> Location
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`
^^^
: () -> 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
^^^
: () -> Prism::node?
4334 4335 4336 |
# File 'lib/prism/node.rb', line 4334 def receiver @receiver end |
#safe_navigation? ⇒ Boolean
:category: Flags &. operator
: () -> bool
4293 4294 4295 |
# File 'lib/prism/node.rb', line 4293 def 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?
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?
4403 4404 4405 |
# File 'lib/prism/node.rb', line 4403 def (repository) repository.enter(node_id, :message_loc) unless .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
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
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
^^^^^
: () -> 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
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=`
^^^
: () -> Symbol
4436 4437 4438 |
# File 'lib/prism/node.rb', line 4436 def write_name @write_name end |