class SyntaxTree::In
In
represents using the in
keyword within the Ruby 2.7+ pattern matching syntax.
case value in pattern end
Attributes
Node
-
the pattern to check against
Statements
-
the expressions to execute if the pattern matched
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 6762 def initialize(pattern:, statements:, consequent:, location:) @pattern = pattern @statements = statements @consequent = consequent @location = location @comments = [] end
Public Instance Methods
Source
# File lib/syntax_tree/node.rb, line 6827 def ===(other) other.is_a?(In) && pattern === other.pattern && statements === other.statements && consequent === other.consequent end
Source
# File lib/syntax_tree/node.rb, line 6770 def accept(visitor) visitor.visit_in(self) end
Source
# File lib/syntax_tree/node.rb, line 6774 def child_nodes [pattern, statements, consequent] end
Also aliased as: deconstruct
Source
# File lib/syntax_tree/node.rb, line 6778 def copy(pattern: nil, statements: nil, consequent: nil, location: nil) node = In.new( pattern: pattern || self.pattern, statements: statements || self.statements, consequent: consequent || self.consequent, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
Source
# File lib/syntax_tree/node.rb, line 6793 def deconstruct_keys(_keys) { pattern: pattern, statements: statements, consequent: consequent, location: location, comments: comments } end
Source
# File lib/syntax_tree/node.rb, line 6803 def format(q) keyword = "in " pattern = self.pattern consequent = self.consequent q.group do q.text(keyword) q.nest(keyword.length) { q.format(pattern) } q.text(" then") if pattern.is_a?(RangeNode) && pattern.right.nil? unless statements.empty? q.indent do q.breakable_force q.format(statements) end end if consequent q.breakable_force q.format(consequent) end end end