class SyntaxTree::In

In represents using the in keyword within the Ruby 2.7+ pattern matching syntax.

case value
in pattern
end

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

consequent[R]
nil | In | Else

the next clause in the chain

pattern[R]
Node

the pattern to check against

statements[R]
Statements

the expressions to execute if the pattern matched

Public Class Methods

new(pattern:, statements:, consequent:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 6747
def initialize(pattern:, statements:, consequent:, location:)
  @pattern = pattern
  @statements = statements
  @consequent = consequent
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 6812
def ===(other)
  other.is_a?(In) && pattern === other.pattern &&
    statements === other.statements && consequent === other.consequent
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 6755
def accept(visitor)
  visitor.visit_in(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 6759
def child_nodes
  [pattern, statements, consequent]
end
Also aliased as: deconstruct
copy(pattern: nil, statements: nil, consequent: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 6763
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
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 6778
def deconstruct_keys(_keys)
  {
    pattern: pattern,
    statements: statements,
    consequent: consequent,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 6788
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