Class: Prism::LocalVariableOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::LocalVariableOrWriteNode
- Defined in:
- lib/prism/node.rb,
lib/prism/desugar_compiler.rb,
ext/prism/api_node.c
Overview
Represents the use of the ‘||=` operator for assignment to a local variable.
target ||= value
^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
attr_reader depth: Integer.
-
#name ⇒ Object
readonly
attr_reader name: Symbol.
-
#value ⇒ Object
readonly
attr_reader value: Prism::node.
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[nil | Node].
-
#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, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value, name: self.name, depth: self.depth) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node, ?name: Symbol, ?depth: Integer) -> LocalVariableOrWriteNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name_loc: Location, operator_loc: Location, value: Prism::node, name: Symbol, depth: Integer }.
-
#desugar ⇒ Object
:nodoc:.
-
#initialize(source, node_id, location, flags, name_loc, operator_loc, value, name, depth) ⇒ LocalVariableOrWriteNode
constructor
Initialize a new LocalVariableOrWriteNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#name_loc ⇒ Object
attr_reader name_loc: Location.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, name_loc, operator_loc, value, name, depth) ⇒ LocalVariableOrWriteNode
Initialize a new LocalVariableOrWriteNode node.
10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 |
# File 'lib/prism/node.rb', line 10678 def initialize(source, node_id, location, flags, name_loc, operator_loc, value, name, depth) @source = source @node_id = node_id @location = location @flags = flags @name_loc = name_loc @operator_loc = operator_loc @value = value @name = name @depth = depth end |
Instance Attribute Details
#depth ⇒ Object (readonly)
attr_reader depth: Integer
10744 10745 10746 |
# File 'lib/prism/node.rb', line 10744 def depth @depth end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
10741 10742 10743 |
# File 'lib/prism/node.rb', line 10741 def name @name end |
#value ⇒ Object (readonly)
attr_reader value: Prism::node
10738 10739 10740 |
# File 'lib/prism/node.rb', line 10738 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
10762 10763 10764 |
# File 'lib/prism/node.rb', line 10762 def self.type :local_variable_or_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.
10768 10769 10770 10771 10772 10773 10774 10775 |
# File 'lib/prism/node.rb', line 10768 def ===(other) other.is_a?(LocalVariableOrWriteNode) && (name_loc.nil? == other.name_loc.nil?) && (operator_loc.nil? == other.operator_loc.nil?) && (value === other.value) && (name === other.name) && (depth === other.depth) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
10691 10692 10693 |
# File 'lib/prism/node.rb', line 10691 def accept(visitor) visitor.visit_local_variable_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
10696 10697 10698 |
# File 'lib/prism/node.rb', line 10696 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
10706 10707 10708 |
# File 'lib/prism/node.rb', line 10706 def comment_targets [name_loc, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
10701 10702 10703 |
# File 'lib/prism/node.rb', line 10701 def compact_child_nodes [value] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value, name: self.name, depth: self.depth) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node, ?name: Symbol, ?depth: Integer) -> LocalVariableOrWriteNode
10711 10712 10713 |
# File 'lib/prism/node.rb', line 10711 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value, name: self.name, depth: self.depth) LocalVariableOrWriteNode.new(source, node_id, location, flags, name_loc, operator_loc, value, name, depth) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name_loc: Location, operator_loc: Location, value: Prism::node, name: Symbol, depth: Integer }
10719 10720 10721 |
# File 'lib/prism/node.rb', line 10719 def deconstruct_keys(keys) { node_id: node_id, location: location, name_loc: name_loc, operator_loc: operator_loc, value: value, name: name, depth: depth } end |
#desugar ⇒ Object
:nodoc:
242 243 244 |
# File 'lib/prism/desugar_compiler.rb', line 242 def desugar # :nodoc: DesugarOrWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile end |
#inspect ⇒ Object
def inspect -> String
10752 10753 10754 |
# File 'lib/prism/node.rb', line 10752 def inspect InspectVisitor.compose(self) end |
#name_loc ⇒ Object
attr_reader name_loc: Location
10724 10725 10726 10727 10728 |
# File 'lib/prism/node.rb', line 10724 def name_loc location = @name_loc return location if location.is_a?(Location) @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ Object
def operator: () -> String
10747 10748 10749 |
# File 'lib/prism/node.rb', line 10747 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
10731 10732 10733 10734 10735 |
# File 'lib/prism/node.rb', line 10731 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
10757 10758 10759 |
# File 'lib/prism/node.rb', line 10757 def type :local_variable_or_write_node end |