Class: YARP::AlternationPatternNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::AlternationPatternNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents an alternation pattern in pattern matching.
foo => bar | baz
^^^^^^^^^
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
attr_reader left: Node.
-
#operator_loc ⇒ Object
readonly
attr_reader operator_loc: Location.
-
#right ⇒ Object
readonly
attr_reader right: 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].
-
#copy(**params) ⇒ Object
def copy: (**params) -> AlternationPatternNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(left, right, operator_loc, location) ⇒ AlternationPatternNode
constructor
def initialize: (left: Node, right: Node, operator_loc: Location, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#operator ⇒ Object
def operator: () -> String.
Constructor Details
#initialize(left, right, operator_loc, location) ⇒ AlternationPatternNode
def initialize: (left: Node, right: Node, operator_loc: Location, location: Location) -> void
95 96 97 98 99 100 |
# File 'lib/yarp/node.rb', line 95 def initialize(left, right, operator_loc, location) @left = left @right = right @operator_loc = operator_loc @location = location end |
Instance Attribute Details
#left ⇒ Object (readonly)
attr_reader left: Node
86 87 88 |
# File 'lib/yarp/node.rb', line 86 def left @left end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
92 93 94 |
# File 'lib/yarp/node.rb', line 92 def operator_loc @operator_loc end |
#right ⇒ Object (readonly)
attr_reader right: Node
89 90 91 |
# File 'lib/yarp/node.rb', line 89 def right @right end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
103 104 105 |
# File 'lib/yarp/node.rb', line 103 def accept(visitor) visitor.visit_alternation_pattern_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
108 109 110 |
# File 'lib/yarp/node.rb', line 108 def child_nodes [left, right] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
113 114 115 |
# File 'lib/yarp/node.rb', line 113 def comment_targets [left, right, operator_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> AlternationPatternNode
118 119 120 121 122 123 124 125 |
# File 'lib/yarp/node.rb', line 118 def copy(**params) AlternationPatternNode.new( params.fetch(:left) { left }, params.fetch(:right) { right }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
131 132 133 |
# File 'lib/yarp/node.rb', line 131 def deconstruct_keys(keys) { left: left, right: right, operator_loc: operator_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/yarp/node.rb', line 140 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── left:\n" inspector << inspector.child_node(left, "│ ") inspector << "├── right:\n" inspector << inspector.child_node(right, "│ ") inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" inspector.to_str end |
#operator ⇒ Object
def operator: () -> String
136 137 138 |
# File 'lib/yarp/node.rb', line 136 def operator operator_loc.slice end |