Class: Prism::ConstantPathTargetNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantPathTargetNode
- Defined in:
- lib/prism/node.rb,
lib/prism/node_ext.rb,
sig/generated/prism/node.rbs,
sig/generated/prism/node_ext.rbs,
ext/prism/api_node.c
Overview
Represents writing to a constant path in a context that doesn't have an explicit value.
Foo::Foo, Bar::Bar = baz
^^^^^^^^ ^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :constant_path_target_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, parent: self.parent, name: self.name, delimiter_loc: self.delimiter_loc, name_loc: self.name_loc) ⇒ ConstantPathTargetNode
:call-seq: copy(**fields) -> ConstantPathTargetNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#delimiter ⇒ String
:call-seq: delimiter -> String.
-
#delimiter_loc ⇒ Location
:category: Locations :call-seq: delimiter_loc -> Location.
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#full_name ⇒ String
Returns the full name of this constant path.
-
#full_name_parts ⇒ Array[Symbol]
Returns the list of parts for the full name of this constant path.
-
#initialize(source, node_id, location, flags, parent, name, delimiter_loc, name_loc) ⇒ ConstantPathTargetNode
constructor
Initialize a new ConstantPathTargetNode node.
-
#inspect ⇒ String
: () -> String.
-
#name ⇒ Symbol?
:call-seq: name -> Symbol | nil.
-
#name_loc ⇒ Location
:category: Locations :call-seq: name_loc -> Location.
-
#parent ⇒ Prism::node?
:call-seq: parent -> Node | nil.
-
#save_delimiter_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the delimiter_loc location using the given saved source so that it can be retrieved later.
-
#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.
-
#type ⇒ :constant_path_target_node
See
Node#type.
Constructor Details
#initialize(source, node_id, location, flags, parent, name, delimiter_loc, name_loc) ⇒ ConstantPathTargetNode
Initialize a new ConstantPathTargetNode node.
: (Source source, Integer node_id, Location location, Integer flags, Prism::node? parent, Symbol? name, Location delimiter_loc, Location name_loc) -> void
9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 |
# File 'lib/prism/node.rb', line 9815 def initialize(source, node_id, location, flags, parent, name, delimiter_loc, name_loc) @source = source @node_id = node_id @location = location @flags = flags @parent = parent @name = name @delimiter_loc = delimiter_loc @name_loc = name_loc end |
Class Method Details
.type ⇒ :constant_path_target_node
See Node.type.
: () -> :constant_path_target_node
9909 9910 9911 |
# File 'lib/prism/node.rb', line 9909 def self.type :constant_path_target_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
9999 10000 10001 10002 10003 10004 10005 |
# File 'lib/prism/node.rb', line 9999 def ===(other) # :nodoc: other.is_a?(ConstantPathTargetNode) && (parent === other.parent) && (name === other.name) && (delimiter_loc.nil? == other.delimiter_loc.nil?) && (name_loc.nil? == other.name_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
9840 9841 9842 |
# File 'lib/prism/node.rb', line 9840 def accept(visitor) visitor.visit_constant_path_target_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
9847 9848 9849 |
# File 'lib/prism/node.rb', line 9847 def child_nodes [parent] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
9864 9865 9866 9867 9868 |
# File 'lib/prism/node.rb', line 9864 def compact_child_nodes compact = [] #: Array[Prism::node] if (parent = self.parent); compact << parent; end compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, parent: self.parent, name: self.name, delimiter_loc: self.delimiter_loc, name_loc: self.name_loc) ⇒ ConstantPathTargetNode
:call-seq:
copy(**fields) -> ConstantPathTargetNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?parent: Prism::node?, ?name: Symbol?, ?delimiter_loc: Location, ?name_loc: Location) -> ConstantPathTargetNode
9876 9877 9878 |
# File 'lib/prism/node.rb', line 9876 def copy(node_id: self.node_id, location: self.location, flags: self.flags, parent: self.parent, name: self.name, delimiter_loc: self.delimiter_loc, name_loc: self.name_loc) ConstantPathTargetNode.new(source, node_id, location, flags, parent, name, delimiter_loc, name_loc) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 |
# File 'lib/prism/node.rb', line 9883 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location parent name delimiter_loc name_loc delimiter]).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 :parent then deconstructed[:parent] = self.parent when :name then deconstructed[:name] = self.name when :delimiter_loc then deconstructed[:delimiter_loc] = self.delimiter_loc when :name_loc then deconstructed[:name_loc] = self.name_loc when :delimiter then deconstructed[:delimiter] = self.delimiter end end end |
#delimiter ⇒ String
:call-seq:
delimiter -> String
Slice the location of delimiter_loc from the source.
: () -> String
9992 9993 9994 |
# File 'lib/prism/node.rb', line 9992 def delimiter delimiter_loc.slice end |
#delimiter_loc ⇒ Location
:category: Locations :call-seq:
delimiter_loc -> Location
Returns the Location represented by delimiter_loc.
: () -> Location
9947 9948 9949 9950 9951 |
# File 'lib/prism/node.rb', line 9947 def delimiter_loc location = @delimiter_loc return location if location.is_a?(Location) @delimiter_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
9855 9856 9857 9858 9859 |
# File 'lib/prism/node.rb', line 9855 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? if (parent = self.parent); yield parent; end end |
#full_name ⇒ String
Returns the full name of this constant path. For example: "Foo::Bar"
: () -> String
289 290 291 |
# File 'lib/prism/node_ext.rb', line 289 def full_name full_name_parts.join("::") end |
#full_name_parts ⇒ Array[Symbol]
Returns the list of parts for the full name of this constant path. For example: [:Foo, :Bar]
: () -> Array
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/prism/node_ext.rb', line 267 def full_name_parts parts = case (parent = self.parent) when ConstantPathNode, ConstantReadNode parent.full_name_parts when nil [:""] else # e.g. self::Foo, (var)::Bar = baz raise ConstantPathNode::DynamicPartsInConstantPathError, "Constant target path contains dynamic parts. Cannot compute full name" end if (name = self.name).nil? raise ConstantPathNode::ErrorRecoveryNodesInConstantPathError, "Constant target path contains error recovery nodes. Cannot compute full name" end parts.push(name) end |
#inspect ⇒ String
: () -> String
9914 9915 9916 |
# File 'lib/prism/node.rb', line 9914 def inspect # :nodoc: InspectVisitor.compose(self) end |
#name ⇒ Symbol?
:call-seq:
name -> Symbol | nil
Returns the name attribute.
: () -> Symbol?
9936 9937 9938 |
# File 'lib/prism/node.rb', line 9936 def name @name end |
#name_loc ⇒ Location
:category: Locations :call-seq:
name_loc -> Location
Returns the Location represented by name_loc.
: () -> Location
9969 9970 9971 9972 9973 |
# File 'lib/prism/node.rb', line 9969 def name_loc location = @name_loc return location if location.is_a?(Location) @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#parent ⇒ Prism::node?
:call-seq:
parent -> Node | nil
Returns the parent attribute.
: () -> Prism::node?
9926 9927 9928 |
# File 'lib/prism/node.rb', line 9926 def parent @parent end |
#save_delimiter_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the delimiter_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
9958 9959 9960 |
# File 'lib/prism/node.rb', line 9958 def save_delimiter_loc(repository) repository.enter(node_id, :delimiter_loc) 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
9980 9981 9982 |
# File 'lib/prism/node.rb', line 9980 def save_name_loc(repository) repository.enter(node_id, :name_loc) end |
#type ⇒ :constant_path_target_node
See Node#type.
: () -> :constant_path_target_node
9902 9903 9904 |
# File 'lib/prism/node.rb', line 9902 def type :constant_path_target_node end |