Class: Prism::CapturePatternNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::CapturePatternNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents assigning to a local variable in pattern matching.
foo => [ => baz]
^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Represents the target of the capture.
-
#value ⇒ Object
readonly
Represents the value to capture.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, target: self.target, operator_loc: self.operator_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node, ?target: LocalVariableTargetNode, ?operator_loc: Location) -> CapturePatternNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, value: Prism::node, target: LocalVariableTargetNode, operator_loc: Location }.
-
#each_child_node {|value| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#initialize(source, node_id, location, flags, value, target, operator_loc) ⇒ CapturePatternNode
constructor
Initialize a new CapturePatternNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
Represents the location of the ‘=>` operator.
-
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, value, target, operator_loc) ⇒ CapturePatternNode
Initialize a new CapturePatternNode node.
3645 3646 3647 3648 3649 3650 3651 3652 3653 |
# File 'lib/prism/node.rb', line 3645 def initialize(source, node_id, location, flags, value, target, operator_loc) @source = source @node_id = node_id @location = location @flags = flags @value = value @target = target @operator_loc = operator_loc end |
Instance Attribute Details
#target ⇒ Object (readonly)
Represents the target of the capture.
foo =>
^^^
3706 3707 3708 |
# File 'lib/prism/node.rb', line 3706 def target @target end |
#value ⇒ Object (readonly)
Represents the value to capture.
foo =>
^^^
3700 3701 3702 |
# File 'lib/prism/node.rb', line 3700 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
3740 3741 3742 |
# File 'lib/prism/node.rb', line 3740 def self.type :capture_pattern_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
3746 3747 3748 3749 3750 3751 |
# File 'lib/prism/node.rb', line 3746 def ===(other) other.is_a?(CapturePatternNode) && (value === other.value) && (target === other.target) && (operator_loc.nil? == other.operator_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
3656 3657 3658 |
# File 'lib/prism/node.rb', line 3656 def accept(visitor) visitor.visit_capture_pattern_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
3661 3662 3663 |
# File 'lib/prism/node.rb', line 3661 def child_nodes [value, target] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
3679 3680 3681 |
# File 'lib/prism/node.rb', line 3679 def comment_targets [value, target, operator_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
3674 3675 3676 |
# File 'lib/prism/node.rb', line 3674 def compact_child_nodes [value, target] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, target: self.target, operator_loc: self.operator_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node, ?target: LocalVariableTargetNode, ?operator_loc: Location) -> CapturePatternNode
3684 3685 3686 |
# File 'lib/prism/node.rb', line 3684 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, target: self.target, operator_loc: self.operator_loc) CapturePatternNode.new(source, node_id, location, flags, value, target, operator_loc) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, value: Prism::node, target: LocalVariableTargetNode, operator_loc: Location }
3692 3693 3694 |
# File 'lib/prism/node.rb', line 3692 def deconstruct_keys(keys) { node_id: node_id, location: location, value: value, target: target, operator_loc: operator_loc } end |
#each_child_node {|value| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator
3666 3667 3668 3669 3670 3671 |
# File 'lib/prism/node.rb', line 3666 def each_child_node return to_enum(:each_child_node) unless block_given? yield value yield target end |
#inspect ⇒ Object
def inspect -> String
3730 3731 3732 |
# File 'lib/prism/node.rb', line 3730 def inspect InspectVisitor.compose(self) end |
#operator ⇒ Object
def operator: () -> String
3725 3726 3727 |
# File 'lib/prism/node.rb', line 3725 def operator operator_loc.slice end |
#operator_loc ⇒ Object
Represents the location of the ‘=>` operator.
foo =>
^^
3712 3713 3714 3715 3716 |
# File 'lib/prism/node.rb', line 3712 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) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
3720 3721 3722 |
# File 'lib/prism/node.rb', line 3720 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
3735 3736 3737 |
# File 'lib/prism/node.rb', line 3735 def type :capture_pattern_node end |