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.
4510 4511 4512 4513 4514 4515 4516 4517 |
# File 'lib/syntax_tree/node.rb', line 4510 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
4508 4509 4510 |
# File 'lib/syntax_tree/node.rb', line 4508 def comments @comments end |
#constant ⇒ Object (readonly)
- nil | untyped
-
the optional constant wrapper
4495 4496 4497 |
# File 'lib/syntax_tree/node.rb', line 4495 def constant @constant end |
#left ⇒ Object (readonly)
- VarField
-
the splat on the left-hand side
4498 4499 4500 |
# File 'lib/syntax_tree/node.rb', line 4498 def left @left end |
#right ⇒ Object (readonly)
- VarField
-
the splat on the right-hand side
4505 4506 4507 |
# File 'lib/syntax_tree/node.rb', line 4505 def right @right end |
#values ⇒ Object (readonly)
- Array[ untyped ]
-
the list of positional expressions in the pattern that
are being matched
4502 4503 4504 |
# File 'lib/syntax_tree/node.rb', line 4502 def values @values end |
Instance Method Details
#accept(visitor) ⇒ Object
4519 4520 4521 |
# File 'lib/syntax_tree/node.rb', line 4519 def accept(visitor) visitor.visit_fndptn(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4523 4524 4525 |
# File 'lib/syntax_tree/node.rb', line 4523 def child_nodes [constant, left, *values, right] end |
#deconstruct_keys(_keys) ⇒ Object
4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 |
# File 'lib/syntax_tree/node.rb', line 4529 def deconstruct_keys(_keys) { constant: constant, left: left, values: values, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 |
# File 'lib/syntax_tree/node.rb', line 4540 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 |