Class: Prism::ConstantPathWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantPathWriteNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents writing to a constant path.
::Foo = 1
^^^^^^^^^
Foo::Bar = 1
^^^^^^^^^^^^
::Foo::Bar = 1
^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
A node representing the constant path being written to.
-
#value ⇒ Object
readonly
The value to write to the constant path.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?operator_loc: Location, ?value: Prism::node) -> ConstantPathWriteNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, target: ConstantPathNode, operator_loc: Location, value: Prism::node }.
-
#initialize(source, node_id, location, flags, target, operator_loc, value) ⇒ ConstantPathWriteNode
constructor
Initialize a new ConstantPathWriteNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
The location of the ‘=` operator.
-
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, target, operator_loc, value) ⇒ ConstantPathWriteNode
Initialize a new ConstantPathWriteNode node.
5528 5529 5530 5531 5532 5533 5534 5535 5536 |
# File 'lib/prism/node.rb', line 5528 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 |
Instance Attribute Details
#target ⇒ Object (readonly)
A node representing the constant path being written to.
Foo::Bar = 1
^^^^^^^^
::Foo = :abc
^^^^^
5578 5579 5580 |
# File 'lib/prism/node.rb', line 5578 def target @target end |
#value ⇒ Object (readonly)
The value to write to the constant path. It can be any [non-void expression](github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
FOO::BAR = :abc
^^^^
5600 5601 5602 |
# File 'lib/prism/node.rb', line 5600 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
5618 5619 5620 |
# File 'lib/prism/node.rb', line 5618 def self.type :constant_path_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.
5624 5625 5626 5627 5628 5629 |
# File 'lib/prism/node.rb', line 5624 def ===(other) other.is_a?(ConstantPathWriteNode) && (target === other.target) && (operator_loc.nil? == other.operator_loc.nil?) && (value === other.value) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
5539 5540 5541 |
# File 'lib/prism/node.rb', line 5539 def accept(visitor) visitor.visit_constant_path_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
5544 5545 5546 |
# File 'lib/prism/node.rb', line 5544 def child_nodes [target, value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
5554 5555 5556 |
# File 'lib/prism/node.rb', line 5554 def comment_targets [target, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
5549 5550 5551 |
# File 'lib/prism/node.rb', line 5549 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) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?operator_loc: Location, ?value: Prism::node) -> ConstantPathWriteNode
5559 5560 5561 |
# File 'lib/prism/node.rb', line 5559 def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value) ConstantPathWriteNode.new(source, node_id, location, flags, target, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, target: ConstantPathNode, operator_loc: Location, value: Prism::node }
5567 5568 5569 |
# File 'lib/prism/node.rb', line 5567 def deconstruct_keys(keys) { node_id: node_id, location: location, target: target, operator_loc: operator_loc, value: value } end |
#inspect ⇒ Object
def inspect -> String
5608 5609 5610 |
# File 'lib/prism/node.rb', line 5608 def inspect InspectVisitor.compose(self) end |
#operator ⇒ Object
def operator: () -> String
5603 5604 5605 |
# File 'lib/prism/node.rb', line 5603 def operator operator_loc.slice end |
#operator_loc ⇒ Object
The location of the ‘=` operator.
::ABC = 123
^
5584 5585 5586 5587 5588 |
# File 'lib/prism/node.rb', line 5584 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) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
5592 5593 5594 |
# File 'lib/prism/node.rb', line 5592 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
5613 5614 5615 |
# File 'lib/prism/node.rb', line 5613 def type :constant_path_write_node end |