class SyntaxTree::Else

Else represents the end of an if, unless, or case chain.

if variable
else
end

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

keyword[R]
Kw

the else keyword

statements[R]
Statements

the expressions to be executed

Public Class Methods

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

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 4853
def ===(other)
  other.is_a?(Else) && keyword === other.keyword &&
    statements === other.statements
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 4809
def accept(visitor)
  visitor.visit_else(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 4813
def child_nodes
  [keyword, statements]
end
Also aliased as: deconstruct
copy(keyword: nil, statements: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 4817
def copy(keyword: nil, statements: nil, location: nil)
  node =
    Else.new(
      keyword: keyword || self.keyword,
      statements: statements || self.statements,
      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 4831
def deconstruct_keys(_keys)
  {
    keyword: keyword,
    statements: statements,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 4840
def format(q)
  q.group do
    q.format(keyword)

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