Class: SyntaxTree::FndPtn
Overview
FndPtn represents matching against a pattern where you find a pattern in an array using the Ruby 3.0+ pattern matching syntax.
case value
in [*, 7, *]
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#constant ⇒ Object
readonly
- nil | untyped
-
the optional constant wrapper.
-
#left ⇒ Object
readonly
- VarField
-
the splat on the left-hand side.
-
#right ⇒ Object
readonly
- VarField
-
the splat on the right-hand side.
-
#values ⇒ Object
readonly
- Array[ untyped ]
-
the list of positional expressions in the pattern that are being matched.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(constant:, left:, values:, right:, location:, comments: []) ⇒ FndPtn
constructor
A new instance of FndPtn.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(constant:, left:, values:, right:, location:, comments: []) ⇒ FndPtn
Returns a new instance of FndPtn.
4582 4583 4584 4585 4586 4587 4588 4589 |
# File 'lib/syntax_tree/node.rb', line 4582 def initialize(constant:, left:, values:, right:, location:, comments: []) @constant = constant @left = left @values = values @right = right @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4580 4581 4582 |
# File 'lib/syntax_tree/node.rb', line 4580 def comments @comments end |
#constant ⇒ Object (readonly)
- nil | untyped
-
the optional constant wrapper
4567 4568 4569 |
# File 'lib/syntax_tree/node.rb', line 4567 def constant @constant end |
#left ⇒ Object (readonly)
- VarField
-
the splat on the left-hand side
4570 4571 4572 |
# File 'lib/syntax_tree/node.rb', line 4570 def left @left end |
#right ⇒ Object (readonly)
- VarField
-
the splat on the right-hand side
4577 4578 4579 |
# File 'lib/syntax_tree/node.rb', line 4577 def right @right end |
#values ⇒ Object (readonly)
- Array[ untyped ]
-
the list of positional expressions in the pattern that
are being matched
4574 4575 4576 |
# File 'lib/syntax_tree/node.rb', line 4574 def values @values end |
Instance Method Details
#accept(visitor) ⇒ Object
4591 4592 4593 |
# File 'lib/syntax_tree/node.rb', line 4591 def accept(visitor) visitor.visit_fndptn(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4595 4596 4597 |
# File 'lib/syntax_tree/node.rb', line 4595 def child_nodes [constant, left, *values, right] end |
#deconstruct_keys(_keys) ⇒ Object
4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 |
# File 'lib/syntax_tree/node.rb', line 4601 def deconstruct_keys(_keys) { constant: constant, left: left, values: values, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 |
# File 'lib/syntax_tree/node.rb', line 4612 def format(q) q.format(constant) if constant q.group(0, "[", "]") do q.text("*") q.format(left) q.comma_breakable q.seplist(values) { |value| q.format(value) } q.comma_breakable q.text("*") q.format(right) end end |