Class: YARP::FindPatternNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::FindPatternNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents a find pattern in pattern matching.
foo in *bar, baz, *qux
^^^^^^^^^^^^^^^^^^^^^^
foo in [*bar, baz, *qux]
^^^^^^^^^^^^^^^^^^^^^^^^
foo in Foo(*bar, baz, *qux)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location?.
-
#constant ⇒ Object
readonly
attr_reader constant: Node?.
-
#left ⇒ Object
readonly
attr_reader left: Node.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location?.
-
#requireds ⇒ Object
readonly
attr_reader requireds: Array.
-
#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].
-
#closing ⇒ Object
def closing: () -> String?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> FindPatternNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(constant, left, requireds, right, opening_loc, closing_loc, location) ⇒ FindPatternNode
constructor
def initialize: (constant: Node?, left: Node, requireds: Array, right: Node, opening_loc: Location?, closing_loc: Location?, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#opening ⇒ Object
def opening: () -> String?.
Constructor Details
#initialize(constant, left, requireds, right, opening_loc, closing_loc, location) ⇒ FindPatternNode
def initialize: (constant: Node?, left: Node, requireds: Array, right: Node, opening_loc: Location?, closing_loc: Location?, location: Location) -> void
4027 4028 4029 4030 4031 4032 4033 4034 4035 |
# File 'lib/yarp/node.rb', line 4027 def initialize(constant, left, requireds, right, opening_loc, closing_loc, location) @constant = constant @left = left @requireds = requireds @right = right @opening_loc = opening_loc @closing_loc = closing_loc @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location?
4024 4025 4026 |
# File 'lib/yarp/node.rb', line 4024 def closing_loc @closing_loc end |
#constant ⇒ Object (readonly)
attr_reader constant: Node?
4009 4010 4011 |
# File 'lib/yarp/node.rb', line 4009 def constant @constant end |
#left ⇒ Object (readonly)
attr_reader left: Node
4012 4013 4014 |
# File 'lib/yarp/node.rb', line 4012 def left @left end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location?
4021 4022 4023 |
# File 'lib/yarp/node.rb', line 4021 def opening_loc @opening_loc end |
#requireds ⇒ Object (readonly)
attr_reader requireds: Array
4015 4016 4017 |
# File 'lib/yarp/node.rb', line 4015 def requireds @requireds end |
#right ⇒ Object (readonly)
attr_reader right: Node
4018 4019 4020 |
# File 'lib/yarp/node.rb', line 4018 def right @right end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
4038 4039 4040 |
# File 'lib/yarp/node.rb', line 4038 def accept(visitor) visitor.visit_find_pattern_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
4043 4044 4045 |
# File 'lib/yarp/node.rb', line 4043 def child_nodes [constant, left, *requireds, right] end |
#closing ⇒ Object
def closing: () -> String?
4079 4080 4081 |
# File 'lib/yarp/node.rb', line 4079 def closing closing_loc&.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
4048 4049 4050 |
# File 'lib/yarp/node.rb', line 4048 def comment_targets [*constant, left, *requireds, right, *opening_loc, *closing_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> FindPatternNode
4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 |
# File 'lib/yarp/node.rb', line 4053 def copy(**params) FindPatternNode.new( params.fetch(:constant) { constant }, params.fetch(:left) { left }, params.fetch(:requireds) { requireds }, params.fetch(:right) { right }, params.fetch(:opening_loc) { opening_loc }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
4069 4070 4071 |
# File 'lib/yarp/node.rb', line 4069 def deconstruct_keys(keys) { constant: constant, left: left, requireds: requireds, right: right, opening_loc: opening_loc, closing_loc: closing_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 |
# File 'lib/yarp/node.rb', line 4083 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) if (constant = self.constant).nil? inspector << "├── constant: ∅\n" else inspector << "├── constant:\n" inspector << constant.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── left:\n" inspector << inspector.child_node(left, "│ ") inspector << "├── requireds: #{inspector.list("#{inspector.prefix}│ ", requireds)}" inspector << "├── right:\n" inspector << inspector.child_node(right, "│ ") inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" inspector.to_str end |
#opening ⇒ Object
def opening: () -> String?
4074 4075 4076 |
# File 'lib/yarp/node.rb', line 4074 def opening opening_loc&.slice end |