Class: Prism::ConstantOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantOrWriteNode
- Defined in:
- lib/prism/node.rb,
lib/prism/desugar_compiler.rb,
sig/generated/prism/node.rbs,
sig/generated/prism/desugar_compiler.rbs,
ext/prism/api_node.c
Overview
Represents the use of the ||= operator for assignment to a constant.
Target ||= value
^^^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :constant_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, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value) ⇒ ConstantOrWriteNode
:call-seq: copy(**fields) -> ConstantOrWriteNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#desugar ⇒ node
: () -> node.
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ ConstantOrWriteNode
constructor
Initialize a new ConstantOrWriteNode node.
-
#inspect ⇒ String
: () -> String.
-
#name ⇒ Symbol
:call-seq: name -> Symbol.
-
#name_loc ⇒ Location
:category: Locations :call-seq: name_loc -> Location.
-
#operator ⇒ String
:call-seq: operator -> String.
-
#operator_loc ⇒ Location
:category: Locations :call-seq: operator_loc -> Location.
-
#save_name_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the name_loc location using the given saved source so that it can be retrieved later.
-
#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.
-
#type ⇒ :constant_or_write_node
See
Node#type. -
#value ⇒ Prism::node
:call-seq: value -> Node.
Constructor Details
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ ConstantOrWriteNode
Initialize a new ConstantOrWriteNode node.
: (Source source, Integer node_id, Location location, Integer flags, Symbol name, Location name_loc, Location operator_loc, Prism::node value) -> void
8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 |
# File 'lib/prism/node.rb', line 8812 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 |
Class Method Details
.type ⇒ :constant_or_write_node
See Node.type.
: () -> :constant_or_write_node
8904 8905 8906 |
# File 'lib/prism/node.rb', line 8904 def self.type :constant_or_write_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
8994 8995 8996 8997 8998 8999 9000 |
# File 'lib/prism/node.rb', line 8994 def ===(other) # :nodoc: 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
See Node.accept.
: (_Visitor visitor) -> untyped
8837 8838 8839 |
# File 'lib/prism/node.rb', line 8837 def accept(visitor) visitor.visit_constant_or_write_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
8844 8845 8846 |
# File 'lib/prism/node.rb', line 8844 def child_nodes [value] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
8861 8862 8863 |
# File 'lib/prism/node.rb', line 8861 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) ⇒ ConstantOrWriteNode
:call-seq:
copy(**fields) -> ConstantOrWriteNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> ConstantOrWriteNode
8871 8872 8873 |
# File 'lib/prism/node.rb', line 8871 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) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 |
# File 'lib/prism/node.rb', line 8878 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location name name_loc 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 :name then deconstructed[:name] = self.name when :name_loc then deconstructed[:name_loc] = self.name_loc 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 |
#desugar ⇒ node
: () -> node
220 221 222 |
# File 'lib/prism/desugar_compiler.rb', line 220 def desugar # :nodoc: DesugarOrWriteDefinedNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
8852 8853 8854 8855 8856 |
# File 'lib/prism/node.rb', line 8852 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield value end |
#inspect ⇒ String
: () -> String
8909 8910 8911 |
# File 'lib/prism/node.rb', line 8909 def inspect # :nodoc: InspectVisitor.compose(self) end |
#name ⇒ Symbol
:call-seq:
name -> Symbol
Returns the name attribute.
: () -> Symbol
8921 8922 8923 |
# File 'lib/prism/node.rb', line 8921 def name @name end |
#name_loc ⇒ Location
:category: Locations :call-seq:
name_loc -> Location
Returns the Location represented by name_loc.
: () -> Location
8932 8933 8934 8935 8936 |
# File 'lib/prism/node.rb', line 8932 def name_loc location = @name_loc return location if location.is_a?(Location) @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
8987 8988 8989 |
# File 'lib/prism/node.rb', line 8987 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
Returns the Location represented by operator_loc.
: () -> Location
8954 8955 8956 8957 8958 |
# File 'lib/prism/node.rb', line 8954 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) ⇒ Relocation::Entry
:category: Repository Save the name_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
8943 8944 8945 |
# File 'lib/prism/node.rb', line 8943 def save_name_loc(repository) repository.enter(node_id, :name_loc) 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
8965 8966 8967 |
# File 'lib/prism/node.rb', line 8965 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ :constant_or_write_node
See Node#type.
: () -> :constant_or_write_node
8897 8898 8899 |
# File 'lib/prism/node.rb', line 8897 def type :constant_or_write_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
Returns the value attribute.
: () -> Prism::node
8975 8976 8977 |
# File 'lib/prism/node.rb', line 8975 def value @value end |