Class: Prism::ConstantWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantWriteNode
- Defined in:
- lib/prism/node.rb,
lib/prism/node_ext.rb,
lib/prism/parse_result/newlines.rb,
sig/generated/prism/node.rbs,
sig/generated/prism/node_ext.rbs,
sig/generated/prism/parse_result/newlines.rbs,
ext/prism/api_node.c
Overview
Class Method Summary collapse
-
.type ⇒ :constant_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, value: self.value, operator_loc: self.operator_loc) ⇒ ConstantWriteNode
:call-seq: copy(**fields) -> ConstantWriteNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#full_name ⇒ String
Returns the full name of this constant.
-
#full_name_parts ⇒ Array[Symbol]
Returns the list of parts for the full name of this constant.
-
#initialize(source, node_id, location, flags, name, name_loc, value, operator_loc) ⇒ ConstantWriteNode
constructor
Initialize a new ConstantWriteNode node.
-
#inspect ⇒ String
: () -> String.
-
#name ⇒ Symbol
:call-seq: name -> Symbol.
-
#name_loc ⇒ Location
:category: Locations :call-seq: name_loc -> Location.
-
#newline_flag!(lines) ⇒ void
: (Array lines) -> void.
-
#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_write_node
See
Node#type. -
#value ⇒ Prism::node
:call-seq: value -> Node.
Constructor Details
#initialize(source, node_id, location, flags, name, name_loc, value, operator_loc) ⇒ ConstantWriteNode
Initialize a new ConstantWriteNode node.
: (Source source, Integer node_id, Location location, Integer flags, Symbol name, Location name_loc, Prism::node value, Location operator_loc) -> void
10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 |
# File 'lib/prism/node.rb', line 10506 def initialize(source, node_id, location, flags, name, name_loc, value, operator_loc) @source = source @node_id = node_id @location = location @flags = flags @name = name @name_loc = name_loc @value = value @operator_loc = operator_loc end |
Class Method Details
.type ⇒ :constant_write_node
See Node.type.
: () -> :constant_write_node
10598 10599 10600 |
# File 'lib/prism/node.rb', line 10598 def self.type :constant_write_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
10720 10721 10722 10723 10724 10725 10726 |
# File 'lib/prism/node.rb', line 10720 def ===(other) # :nodoc: other.is_a?(ConstantWriteNode) && (name === other.name) && (name_loc.nil? == other.name_loc.nil?) && (value === other.value) && (operator_loc.nil? == other.operator_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
10531 10532 10533 |
# File 'lib/prism/node.rb', line 10531 def accept(visitor) visitor.visit_constant_write_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
10538 10539 10540 |
# File 'lib/prism/node.rb', line 10538 def child_nodes [value] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
10555 10556 10557 |
# File 'lib/prism/node.rb', line 10555 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, value: self.value, operator_loc: self.operator_loc) ⇒ ConstantWriteNode
:call-seq:
copy(**fields) -> ConstantWriteNode
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, ?value: Prism::node, ?operator_loc: Location) -> ConstantWriteNode
10565 10566 10567 |
# File 'lib/prism/node.rb', line 10565 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, value: self.value, operator_loc: self.operator_loc) ConstantWriteNode.new(source, node_id, location, flags, name, name_loc, value, operator_loc) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 |
# File 'lib/prism/node.rb', line 10572 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location name name_loc value operator_loc 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 :value then deconstructed[:value] = self.value when :operator_loc then deconstructed[:operator_loc] = self.operator_loc 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
10546 10547 10548 10549 10550 |
# File 'lib/prism/node.rb', line 10546 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield value end |
#full_name ⇒ String
Returns the full name of this constant. For example: "Foo"
: () -> String
210 211 212 |
# File 'lib/prism/node_ext.rb', line 210 def full_name name.to_s end |
#full_name_parts ⇒ Array[Symbol]
Returns the list of parts for the full name of this constant. For example: [:Foo]
: () -> Array
203 204 205 |
# File 'lib/prism/node_ext.rb', line 203 def full_name_parts [name] end |
#inspect ⇒ String
: () -> String
10603 10604 10605 |
# File 'lib/prism/node.rb', line 10603 def inspect # :nodoc: InspectVisitor.compose(self) end |
#name ⇒ Symbol
:call-seq:
name -> Symbol
The name of the constant.
Foo = :bar # name `:Foo`
XYZ = 1 # name `:XYZ`
: () -> Symbol
10623 10624 10625 |
# File 'lib/prism/node.rb', line 10623 def name @name end |
#name_loc ⇒ Location
:category: Locations :call-seq:
name_loc -> Location
The Location of the constant name.
FOO = 1
^^^
: () -> Location
10641 10642 10643 10644 10645 |
# File 'lib/prism/node.rb', line 10641 def name_loc location = @name_loc return location if location.is_a?(Location) @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#newline_flag!(lines) ⇒ void
This method returns an undefined value.
: (Array lines) -> void
326 327 328 |
# File 'lib/prism/parse_result/newlines.rb', line 326 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
10713 10714 10715 |
# File 'lib/prism/node.rb', line 10713 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
The Location of the = operator.
FOO = :bar
^
: () -> Location
10690 10691 10692 10693 10694 |
# File 'lib/prism/node.rb', line 10690 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
10652 10653 10654 |
# File 'lib/prism/node.rb', line 10652 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
10701 10702 10703 |
# File 'lib/prism/node.rb', line 10701 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ :constant_write_node
See Node#type.
: () -> :constant_write_node
10591 10592 10593 |
# File 'lib/prism/node.rb', line 10591 def type :constant_write_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
The value to write to the constant. It can be any non-void expression.
FOO = :bar
^^^^
MyClass = Class.new
^^^^^^^^^
: () -> Prism::node
10672 10673 10674 |
# File 'lib/prism/node.rb', line 10672 def value @value end |