Class: Prism::ConstantOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantOrWriteNode
- 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 constant.
Target ||= value
^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#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: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> ConstantOrWriteNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }.
-
#desugar ⇒ Object
:nodoc:.
-
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ ConstantOrWriteNode
constructor
Initialize a new ConstantOrWriteNode 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, name_loc, operator_loc, value) ⇒ ConstantOrWriteNode
Initialize a new ConstantOrWriteNode node.
4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 |
# File 'lib/prism/node.rb', line 4896 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) @source = source @node_id = node_id @location = location @flags = flags @name = name @name_loc = name_loc @operator_loc = operator_loc @value = value end |
Instance Attribute Details
#name ⇒ Object (readonly)
attr_reader name: Symbol
4941 4942 4943 |
# File 'lib/prism/node.rb', line 4941 def name @name end |
#value ⇒ Object (readonly)
attr_reader value: Prism::node
4970 4971 4972 |
# File 'lib/prism/node.rb', line 4970 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
4988 4989 4990 |
# File 'lib/prism/node.rb', line 4988 def self.type :constant_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.
4994 4995 4996 4997 4998 4999 5000 |
# File 'lib/prism/node.rb', line 4994 def ===(other) other.is_a?(ConstantOrWriteNode) && (name === other.name) && (name_loc.nil? == other.name_loc.nil?) && (operator_loc.nil? == other.operator_loc.nil?) && (value === other.value) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
4908 4909 4910 |
# File 'lib/prism/node.rb', line 4908 def accept(visitor) visitor.visit_constant_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
4913 4914 4915 |
# File 'lib/prism/node.rb', line 4913 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
4923 4924 4925 |
# File 'lib/prism/node.rb', line 4923 def comment_targets [name_loc, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
4918 4919 4920 |
# File 'lib/prism/node.rb', line 4918 def compact_child_nodes [value] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> ConstantOrWriteNode
4928 4929 4930 |
# File 'lib/prism/node.rb', line 4928 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value) ConstantOrWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
4936 4937 4938 |
# File 'lib/prism/node.rb', line 4936 def deconstruct_keys(keys) { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value } end |
#desugar ⇒ Object
:nodoc:
189 190 191 |
# File 'lib/prism/desugar_compiler.rb', line 189 def desugar # :nodoc: DesugarOrWriteDefinedNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile end |
#inspect ⇒ Object
def inspect -> String
4978 4979 4980 |
# File 'lib/prism/node.rb', line 4978 def inspect InspectVisitor.compose(self) end |
#name_loc ⇒ Object
attr_reader name_loc: Location
4944 4945 4946 4947 4948 |
# File 'lib/prism/node.rb', line 4944 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
4973 4974 4975 |
# File 'lib/prism/node.rb', line 4973 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
4957 4958 4959 4960 4961 |
# File 'lib/prism/node.rb', line 4957 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.
4952 4953 4954 |
# File 'lib/prism/node.rb', line 4952 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.
4965 4966 4967 |
# File 'lib/prism/node.rb', line 4965 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`.
4983 4984 4985 |
# File 'lib/prism/node.rb', line 4983 def type :constant_or_write_node end |