class SyntaxTree::Elsif

Elsif represents another clause in an if or unless chain.

if variable
elsif other_variable
end

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

consequent[R]
nil | Elsif | Else

the next clause in the chain

predicate[R]
Node

the expression to be checked

statements[R]
Statements

the expressions to be executed

Public Class Methods

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

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 4942
def ===(other)
  other.is_a?(Elsif) && predicate === other.predicate &&
    statements === other.statements && consequent === other.consequent
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 4886
def accept(visitor)
  visitor.visit_elsif(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 4890
def child_nodes
  [predicate, statements, consequent]
end
Also aliased as: deconstruct
copy(predicate: nil, statements: nil, consequent: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 4894
def copy(predicate: nil, statements: nil, consequent: nil, location: nil)
  node =
    Elsif.new(
      predicate: predicate || self.predicate,
      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 4909
def deconstruct_keys(_keys)
  {
    predicate: predicate,
    statements: statements,
    consequent: consequent,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 4919
def format(q)
  q.group do
    q.group do
      q.text("elsif ")
      q.nest("elsif".length - 1) { q.format(predicate) }
    end

    unless statements.empty?
      q.indent do
        q.breakable_force
        q.format(statements)
      end
    end

    if consequent
      q.group do
        q.breakable_force
        q.format(consequent)
      end
    end
  end
end