Class: Prism::ConstantPathAndWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantPathAndWriteNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents the use of the ‘&&=` operator for assignment to a constant path.
Parent::Child &&= value
^^^^^^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#operator_loc ⇒ Object
readonly
attr_reader operator_loc: Location.
-
#target ⇒ Object
readonly
attr_reader target: ConstantPathNode.
-
#value ⇒ Object
readonly
attr_reader value: Node.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(**params) ⇒ Object
def copy: (**params) -> ConstantPathAndWriteNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(target, operator_loc, value, location) ⇒ ConstantPathAndWriteNode
constructor
def initialize: (target: ConstantPathNode, operator_loc: Location, value: Node, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#operator ⇒ Object
def operator: () -> String.
-
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform.
Constructor Details
#initialize(target, operator_loc, value, location) ⇒ ConstantPathAndWriteNode
def initialize: (target: ConstantPathNode, operator_loc: Location, value: Node, location: Location) -> void
3705 3706 3707 3708 3709 3710 |
# File 'lib/prism/node.rb', line 3705 def initialize(target, operator_loc, value, location) @target = target @operator_loc = operator_loc @value = value @location = location end |
Instance Attribute Details
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
3699 3700 3701 |
# File 'lib/prism/node.rb', line 3699 def operator_loc @operator_loc end |
#target ⇒ Object (readonly)
attr_reader target: ConstantPathNode
3696 3697 3698 |
# File 'lib/prism/node.rb', line 3696 def target @target end |
#value ⇒ Object (readonly)
attr_reader value: Node
3702 3703 3704 |
# File 'lib/prism/node.rb', line 3702 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
3713 3714 3715 |
# File 'lib/prism/node.rb', line 3713 def accept(visitor) visitor.visit_constant_path_and_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
3718 3719 3720 |
# File 'lib/prism/node.rb', line 3718 def child_nodes [target, value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
3728 3729 3730 |
# File 'lib/prism/node.rb', line 3728 def comment_targets [target, operator_loc, value] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
3723 3724 3725 |
# File 'lib/prism/node.rb', line 3723 def compact_child_nodes [target, value] end |
#copy(**params) ⇒ Object
def copy: (**params) -> ConstantPathAndWriteNode
3733 3734 3735 3736 3737 3738 3739 3740 |
# File 'lib/prism/node.rb', line 3733 def copy(**params) ConstantPathAndWriteNode.new( params.fetch(:target) { target }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
3746 3747 3748 |
# File 'lib/prism/node.rb', line 3746 def deconstruct_keys(keys) { target: target, operator_loc: operator_loc, value: value, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
3755 3756 3757 3758 3759 3760 3761 3762 3763 |
# File 'lib/prism/node.rb', line 3755 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── target:\n" inspector << inspector.child_node(target, "│ ") inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" inspector << "└── value:\n" inspector << inspector.child_node(value, " ") inspector.to_str end |
#operator ⇒ Object
def operator: () -> String
3751 3752 3753 |
# File 'lib/prism/node.rb', line 3751 def operator operator_loc.slice end |
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform. Usually this is done by calling ‘[cls1, cls2].include?(node.class)` or putting the node into a case statement and doing `case node; when cls1; when cls2; end`. Both of these approaches are relatively slow because of the constant lookups, method calls, and/or array allocations.
Instead, you can call #type, which will return to you a symbol that you can use for comparison. This is faster than the other approaches because it uses a single integer comparison, but also because if you’re on CRuby you can take advantage of the fact that case statements with all symbol keys will use a jump table.
def type: () -> Symbol
3779 3780 3781 |
# File 'lib/prism/node.rb', line 3779 def type :constant_path_and_write_node end |