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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(pattern:, statements:, consequent:, location:, comments: []) ⇒ In
Returns a new instance of In.
5674 5675 5676 5677 5678 5679 5680 |
# File 'lib/syntax_tree/node.rb', line 5674 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
5672 5673 5674 |
# File 'lib/syntax_tree/node.rb', line 5672 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil | In | Else
-
the next clause in the chain
5669 5670 5671 |
# File 'lib/syntax_tree/node.rb', line 5669 def consequent @consequent end |
#pattern ⇒ Object (readonly)
- untyped
-
the pattern to check against
5663 5664 5665 |
# File 'lib/syntax_tree/node.rb', line 5663 def pattern @pattern end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to execute if the pattern matched
5666 5667 5668 |
# File 'lib/syntax_tree/node.rb', line 5666 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
5682 5683 5684 |
# File 'lib/syntax_tree/node.rb', line 5682 def accept(visitor) visitor.visit_in(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5686 5687 5688 |
# File 'lib/syntax_tree/node.rb', line 5686 def child_nodes [pattern, statements, consequent] end |
#deconstruct_keys(_keys) ⇒ Object
5692 5693 5694 5695 5696 5697 5698 5699 5700 |
# File 'lib/syntax_tree/node.rb', line 5692 def deconstruct_keys(_keys) { pattern: pattern, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 |
# File 'lib/syntax_tree/node.rb', line 5702 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 |