Class: SyntaxTree::In
Overview
In represents using the in keyword within the Ruby 2.7+ pattern matching syntax.
case value
in pattern
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#consequent ⇒ Object
readonly
- nil | In | Else
-
the next clause in the chain.
-
#pattern ⇒ Object
readonly
- untyped
-
the pattern to check against.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to execute if the pattern 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(pattern:, statements:, consequent:, location:, comments: []) ⇒ In
constructor
A new instance of In.
Methods inherited from Node
Constructor Details
#initialize(pattern:, statements:, consequent:, location:, comments: []) ⇒ In
Returns a new instance of In.
5502 5503 5504 5505 5506 5507 5508 |
# File 'lib/syntax_tree/node.rb', line 5502 def initialize(pattern:, statements:, consequent:, location:, comments: []) @pattern = pattern @statements = statements @consequent = consequent @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5500 5501 5502 |
# File 'lib/syntax_tree/node.rb', line 5500 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil | In | Else
-
the next clause in the chain
5497 5498 5499 |
# File 'lib/syntax_tree/node.rb', line 5497 def consequent @consequent end |
#pattern ⇒ Object (readonly)
- untyped
-
the pattern to check against
5491 5492 5493 |
# File 'lib/syntax_tree/node.rb', line 5491 def pattern @pattern end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to execute if the pattern matched
5494 5495 5496 |
# File 'lib/syntax_tree/node.rb', line 5494 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
5510 5511 5512 |
# File 'lib/syntax_tree/node.rb', line 5510 def accept(visitor) visitor.visit_in(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5514 5515 5516 |
# File 'lib/syntax_tree/node.rb', line 5514 def child_nodes [pattern, statements, consequent] end |
#deconstruct_keys(keys) ⇒ Object
5520 5521 5522 5523 5524 5525 5526 5527 5528 |
# File 'lib/syntax_tree/node.rb', line 5520 def deconstruct_keys(keys) { pattern: pattern, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 |
# File 'lib/syntax_tree/node.rb', line 5530 def format(q) keyword = "in " q.group do q.text(keyword) q.nest(keyword.length) { q.format(pattern) } unless statements.empty? q.indent do q.breakable(force: true) q.format(statements) end end if consequent q.breakable(force: true) q.format(consequent) end end end |