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.
4109 4110 4111 4112 4113 4114 4115 4116 |
# File 'lib/syntax_tree/node.rb', line 4109 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
4107 4108 4109 |
# File 'lib/syntax_tree/node.rb', line 4107 def comments @comments end |
#constant ⇒ Object (readonly)
- nil | untyped
-
the optional constant wrapper
4094 4095 4096 |
# File 'lib/syntax_tree/node.rb', line 4094 def constant @constant end |
#left ⇒ Object (readonly)
- VarField
-
the splat on the left-hand side
4097 4098 4099 |
# File 'lib/syntax_tree/node.rb', line 4097 def left @left end |
#right ⇒ Object (readonly)
- VarField
-
the splat on the right-hand side
4104 4105 4106 |
# File 'lib/syntax_tree/node.rb', line 4104 def right @right end |
#values ⇒ Object (readonly)
- Array[ untyped ]
-
the list of positional expressions in the pattern that
are being matched
4101 4102 4103 |
# File 'lib/syntax_tree/node.rb', line 4101 def values @values end |
Instance Method Details
#accept(visitor) ⇒ Object
4118 4119 4120 |
# File 'lib/syntax_tree/node.rb', line 4118 def accept(visitor) visitor.visit_fndptn(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4122 4123 4124 |
# File 'lib/syntax_tree/node.rb', line 4122 def child_nodes [constant, left, *values, right] end |
#deconstruct_keys(keys) ⇒ Object
4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 |
# File 'lib/syntax_tree/node.rb', line 4128 def deconstruct_keys(keys) { constant: constant, left: left, values: values, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 |
# File 'lib/syntax_tree/node.rb', line 4139 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 |