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
Constructor Details
#initialize(constant:, left:, values:, right:, location:, comments: []) ⇒ FndPtn
Returns a new instance of FndPtn.
4471 4472 4473 4474 4475 4476 4477 4478 |
# File 'lib/syntax_tree/node.rb', line 4471 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
4469 4470 4471 |
# File 'lib/syntax_tree/node.rb', line 4469 def comments @comments end |
#constant ⇒ Object (readonly)
- nil | untyped
-
the optional constant wrapper
4456 4457 4458 |
# File 'lib/syntax_tree/node.rb', line 4456 def constant @constant end |
#left ⇒ Object (readonly)
- VarField
-
the splat on the left-hand side
4459 4460 4461 |
# File 'lib/syntax_tree/node.rb', line 4459 def left @left end |
#right ⇒ Object (readonly)
- VarField
-
the splat on the right-hand side
4466 4467 4468 |
# File 'lib/syntax_tree/node.rb', line 4466 def right @right end |
#values ⇒ Object (readonly)
- Array[ untyped ]
-
the list of positional expressions in the pattern that
are being matched
4463 4464 4465 |
# File 'lib/syntax_tree/node.rb', line 4463 def values @values end |
Instance Method Details
#accept(visitor) ⇒ Object
4480 4481 4482 |
# File 'lib/syntax_tree/node.rb', line 4480 def accept(visitor) visitor.visit_fndptn(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4484 4485 4486 |
# File 'lib/syntax_tree/node.rb', line 4484 def child_nodes [constant, left, *values, right] end |
#deconstruct_keys(keys) ⇒ Object
4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 |
# File 'lib/syntax_tree/node.rb', line 4490 def deconstruct_keys(keys) { constant: constant, left: left, values: values, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 |
# File 'lib/syntax_tree/node.rb', line 4501 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 |