Class: Prism::ConstantPathWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantPathWriteNode
- Defined in:
- lib/prism/node.rb,
lib/prism/parse_result/newlines.rb,
sig/generated/prism/node.rbs,
sig/generated/prism/parse_result/newlines.rbs,
ext/prism/api_node.c
Overview
Represents writing to a constant path.
::Foo = 1
^^^^^^^^^
Foo::Bar = 1
^^^^^^^^^^^^
::Foo::Bar = 1
^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :constant_path_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, target: self.target, operator_loc: self.operator_loc, value: self.value) ⇒ ConstantPathWriteNode
:call-seq: copy(**fields) -> ConstantPathWriteNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, target, operator_loc, value) ⇒ ConstantPathWriteNode
constructor
Initialize a new ConstantPathWriteNode node.
-
#inspect ⇒ String
: () -> String.
-
#newline_flag!(lines) ⇒ void
: (Array lines) -> void.
-
#operator ⇒ String
:call-seq: operator -> String.
-
#operator_loc ⇒ Location
:category: Locations :call-seq: operator_loc -> Location.
-
#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.
-
#target ⇒ ConstantPathNode
:call-seq: target -> ConstantPathNode.
-
#type ⇒ :constant_path_write_node
See
Node#type. -
#value ⇒ Prism::node
:call-seq: value -> Node.
Constructor Details
#initialize(source, node_id, location, flags, target, operator_loc, value) ⇒ ConstantPathWriteNode
Initialize a new ConstantPathWriteNode node.
: (Source source, Integer node_id, Location location, Integer flags, ConstantPathNode target, Location operator_loc, Prism::node value) -> void
10030 10031 10032 10033 10034 10035 10036 10037 10038 |
# File 'lib/prism/node.rb', line 10030 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 |
Class Method Details
.type ⇒ :constant_path_write_node
See Node.type.
: () -> :constant_path_write_node
10121 10122 10123 |
# File 'lib/prism/node.rb', line 10121 def self.type :constant_path_write_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
10213 10214 10215 10216 10217 10218 |
# File 'lib/prism/node.rb', line 10213 def ===(other) # :nodoc: other.is_a?(ConstantPathWriteNode) && (target === other.target) && (operator_loc.nil? == other.operator_loc.nil?) && (value === other.value) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
10054 10055 10056 |
# File 'lib/prism/node.rb', line 10054 def accept(visitor) visitor.visit_constant_path_write_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
10061 10062 10063 |
# File 'lib/prism/node.rb', line 10061 def child_nodes [target, value] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
10079 10080 10081 |
# File 'lib/prism/node.rb', line 10079 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) ⇒ ConstantPathWriteNode
:call-seq:
copy(**fields) -> ConstantPathWriteNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?operator_loc: Location, ?value: Prism::node) -> ConstantPathWriteNode
10089 10090 10091 |
# File 'lib/prism/node.rb', line 10089 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) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 |
# File 'lib/prism/node.rb', line 10096 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location target 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 :target then deconstructed[:target] = self.target 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 |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
10069 10070 10071 10072 10073 10074 |
# File 'lib/prism/node.rb', line 10069 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield target yield value end |
#inspect ⇒ String
: () -> String
10126 10127 10128 |
# File 'lib/prism/node.rb', line 10126 def inspect # :nodoc: InspectVisitor.compose(self) end |
#newline_flag!(lines) ⇒ void
This method returns an undefined value.
: (Array lines) -> void
333 334 335 |
# File 'lib/prism/parse_result/newlines.rb', line 333 def newline_flag!(lines) # :nodoc: value.newline_flag!(lines) end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
10206 10207 10208 |
# File 'lib/prism/node.rb', line 10206 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
The Location of the = operator.
::ABC = 123
^
: () -> Location
10166 10167 10168 10169 10170 |
# File 'lib/prism/node.rb', line 10166 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) ⇒ 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
10177 10178 10179 |
# File 'lib/prism/node.rb', line 10177 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#target ⇒ ConstantPathNode
:call-seq:
target -> ConstantPathNode
A node representing the constant path being written to.
Foo::Bar = 1
^^^^^^^^
::Foo = :abc
^^^^^
: () -> ConstantPathNode
10148 10149 10150 |
# File 'lib/prism/node.rb', line 10148 def target @target end |
#type ⇒ :constant_path_write_node
See Node#type.
: () -> :constant_path_write_node
10114 10115 10116 |
# File 'lib/prism/node.rb', line 10114 def type :constant_path_write_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
The value to write to the constant path. It can be any non-void expression.
FOO::BAR = :abc
^^^^
: () -> Prism::node
10194 10195 10196 |
# File 'lib/prism/node.rb', line 10194 def value @value end |