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.
-
#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:.
-
#each_child_node {|value| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#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.
-
#save_name_loc(repository) ⇒ Object
Save the name_loc location using the given saved source so that it can be retrieved later.
-
#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, name_loc, operator_loc, value, name, depth) ⇒ LocalVariableOrWriteNode
Initialize a new LocalVariableOrWriteNode node.
12765 12766 12767 12768 12769 12770 12771 12772 12773 12774 12775 |
# File 'lib/prism/node.rb', line 12765 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
12850 12851 12852 |
# File 'lib/prism/node.rb', line 12850 def depth @depth end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
12847 12848 12849 |
# File 'lib/prism/node.rb', line 12847 def name @name end |
#value ⇒ Object (readonly)
attr_reader value: Prism::node
12844 12845 12846 |
# File 'lib/prism/node.rb', line 12844 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
12868 12869 12870 |
# File 'lib/prism/node.rb', line 12868 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.
12874 12875 12876 12877 12878 12879 12880 12881 |
# File 'lib/prism/node.rb', line 12874 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
12778 12779 12780 |
# File 'lib/prism/node.rb', line 12778 def accept(visitor) visitor.visit_local_variable_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
12783 12784 12785 |
# File 'lib/prism/node.rb', line 12783 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
12800 12801 12802 |
# File 'lib/prism/node.rb', line 12800 def comment_targets [name_loc, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
12795 12796 12797 |
# File 'lib/prism/node.rb', line 12795 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
12805 12806 12807 |
# File 'lib/prism/node.rb', line 12805 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 }
12813 12814 12815 |
# File 'lib/prism/node.rb', line 12813 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:
243 244 245 |
# File 'lib/prism/desugar_compiler.rb', line 243 def desugar # :nodoc: DesugarOrWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile end |
#each_child_node {|value| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator
12788 12789 12790 12791 12792 |
# File 'lib/prism/node.rb', line 12788 def each_child_node return to_enum(:each_child_node) unless block_given? yield value end |
#inspect ⇒ Object
def inspect -> String
12858 12859 12860 |
# File 'lib/prism/node.rb', line 12858 def inspect InspectVisitor.compose(self) end |
#name_loc ⇒ Object
attr_reader name_loc: Location
12818 12819 12820 12821 12822 |
# File 'lib/prism/node.rb', line 12818 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
12853 12854 12855 |
# File 'lib/prism/node.rb', line 12853 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
12831 12832 12833 12834 12835 |
# File 'lib/prism/node.rb', line 12831 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#save_name_loc(repository) ⇒ Object
Save the name_loc location using the given saved source so that it can be retrieved later.
12826 12827 12828 |
# File 'lib/prism/node.rb', line 12826 def save_name_loc(repository) repository.enter(node_id, :name_loc) end |
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
12839 12840 12841 |
# File 'lib/prism/node.rb', line 12839 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`.
12863 12864 12865 |
# File 'lib/prism/node.rb', line 12863 def type :local_variable_or_write_node end |