A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://ruby-syntax-tree.github.io/syntax_tree/SyntaxTree/In.html below:

class SyntaxTree::In - RDoc Documentation

  1. SyntaxTree::
  2. In
class SyntaxTree::In

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

case value
in pattern
end
Attributes
nil | In | Else

the next clause in the chain

Node

the pattern to check against

Statements

the expressions to execute if the pattern matched

Public Class Methods

Source

def initialize(pattern:, statements:, consequent:, location:)
  @pattern = pattern
  @statements = statements
  @consequent = consequent
  @location = location
  @comments = []
end
Public Instance Methods

Source

def ===(other)
  other.is_a?(In) && pattern === other.pattern &&
    statements === other.statements && consequent === other.consequent
end

Source

def accept(visitor)
  visitor.visit_in(self)
end

Source

def child_nodes
  [pattern, statements, consequent]
end

Source

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

def deconstruct_keys(_keys)
  {
    pattern: pattern,
    statements: statements,
    consequent: consequent,
    location: location,
    comments: comments
  }
end

Source

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4