Class: Prism::ConstantPathOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantPathOrWriteNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Represents the use of the ||= operator for assignment to a constant path.
Parent::Child ||= value
^^^^^^^^^^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :constant_path_or_write_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#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, target: self.target, operator_loc: self.operator_loc, value: self.value) ⇒ ConstantPathOrWriteNode
:call-seq: copy(**fields) -> ConstantPathOrWriteNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, target, operator_loc, value) ⇒ ConstantPathOrWriteNode
constructor
Initialize a new ConstantPathOrWriteNode node.
-
#inspect ⇒ String
: () -> String.
-
#operator ⇒ String
:call-seq: operator -> String.
-
#operator_loc ⇒ Location
:category: Locations :call-seq: operator_loc -> Location.
-
#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.
-
#target ⇒ ConstantPathNode
:call-seq: target -> ConstantPathNode.
-
#type ⇒ :constant_path_or_write_node
See
Node#type. -
#value ⇒ Prism::node
:call-seq: value -> Node.
Constructor Details
#initialize(source, node_id, location, flags, target, operator_loc, value) ⇒ ConstantPathOrWriteNode
Initialize a new ConstantPathOrWriteNode node.
: (Source source, Integer node_id, Location location, Integer flags, ConstantPathNode target, Location operator_loc, Prism::node value) -> void
9631 9632 9633 9634 9635 9636 9637 9638 9639 |
# File 'lib/prism/node.rb', line 9631 def initialize(source, node_id, location, flags, target, operator_loc, value) @source = source @node_id = node_id @location = location @flags = flags @target = target @operator_loc = operator_loc @value = value end |
Class Method Details
.type ⇒ :constant_path_or_write_node
See Node.type.
: () -> :constant_path_or_write_node
9722 9723 9724 |
# File 'lib/prism/node.rb', line 9722 def self.type :constant_path_or_write_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
9790 9791 9792 9793 9794 9795 |
# File 'lib/prism/node.rb', line 9790 def ===(other) # :nodoc: other.is_a?(ConstantPathOrWriteNode) && (target === other.target) && (operator_loc.nil? == other.operator_loc.nil?) && (value === other.value) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
9655 9656 9657 |
# File 'lib/prism/node.rb', line 9655 def accept(visitor) visitor.visit_constant_path_or_write_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
9662 9663 9664 |
# File 'lib/prism/node.rb', line 9662 def child_nodes [target, value] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
9680 9681 9682 |
# File 'lib/prism/node.rb', line 9680 def compact_child_nodes [target, value] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value) ⇒ ConstantPathOrWriteNode
:call-seq:
copy(**fields) -> ConstantPathOrWriteNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?operator_loc: Location, ?value: Prism::node) -> ConstantPathOrWriteNode
9690 9691 9692 |
# File 'lib/prism/node.rb', line 9690 def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value) ConstantPathOrWriteNode.new(source, node_id, location, flags, target, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 |
# File 'lib/prism/node.rb', line 9697 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location target operator_loc value 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 :target then deconstructed[:target] = self.target when :operator_loc then deconstructed[:operator_loc] = self.operator_loc when :value then deconstructed[:value] = self.value 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
9670 9671 9672 9673 9674 9675 |
# File 'lib/prism/node.rb', line 9670 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield target yield value end |
#inspect ⇒ String
: () -> String
9727 9728 9729 |
# File 'lib/prism/node.rb', line 9727 def inspect # :nodoc: InspectVisitor.compose(self) end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
9783 9784 9785 |
# File 'lib/prism/node.rb', line 9783 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
Returns the Location represented by operator_loc.
: () -> Location
9750 9751 9752 9753 9754 |
# File 'lib/prism/node.rb', line 9750 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) 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
9761 9762 9763 |
# File 'lib/prism/node.rb', line 9761 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#target ⇒ ConstantPathNode
:call-seq:
target -> ConstantPathNode
Returns the target attribute.
: () -> ConstantPathNode
9739 9740 9741 |
# File 'lib/prism/node.rb', line 9739 def target @target end |
#type ⇒ :constant_path_or_write_node
See Node#type.
: () -> :constant_path_or_write_node
9715 9716 9717 |
# File 'lib/prism/node.rb', line 9715 def type :constant_path_or_write_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
Returns the value attribute.
: () -> Prism::node
9771 9772 9773 |
# File 'lib/prism/node.rb', line 9771 def value @value end |