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/When.html below:

class SyntaxTree::When - RDoc Documentation

  1. SyntaxTree::
  2. When
class SyntaxTree::When

When represents a when clause in a case chain.

case value
when predicate
end
Constants
SEPARATOR

We’re going to keep a single instance of this separator around so we don’t have to allocate a new one every time we format a when clause.

Attributes
Args

the arguments to the when clause

nil | Else | When

the next clause in the chain

Public Class Methods

Source

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

Source

def ===(other)
  other.is_a?(When) && arguments === other.arguments &&
    statements === other.statements && consequent === other.consequent
end

Source

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

Source

def child_nodes
  [arguments, statements, consequent]
end

Source

def copy(arguments: nil, statements: nil, consequent: nil, location: nil)
  node =
    When.new(
      arguments: arguments || self.arguments,
      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)
  {
    arguments: arguments,
    statements: statements,
    consequent: consequent,
    location: location,
    comments: comments
  }
end

Source

def format(q)
  keyword = "when "

  q.group do
    q.group do
      q.text(keyword)
      q.nest(keyword.length) do
        if arguments.comments.any?
          q.format(arguments)
        else
          q.seplist(arguments.parts, SEPARATOR) { |part| q.format(part) }
        end

        
        
        
        last = arguments.parts.last
        q.text(" then") if last.is_a?(RangeNode) && !last.right
      end
    end

    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