class Prism::ElseNode

Represents an else clause in a case, if, or unless statement.

if a then b else c end
            ^^^^^^^^^^

Attributes

statements[R]

attr_reader statements: StatementsNode?

Public Class Methods

new(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc) click to toggle source

Initialize a new ElseNode node.

# File lib/prism/node.rb, line 6038
def initialize(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @else_keyword_loc = else_keyword_loc
  @statements = statements
  @end_keyword_loc = end_keyword_loc
end
type() click to toggle source

Return a symbol representation of this node type. See Node::type.

# File lib/prism/node.rb, line 6139
def self.type
  :else_node
end

Public Instance Methods

===(other) click to toggle source

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.

# File lib/prism/node.rb, line 6145
def ===(other)
  other.is_a?(ElseNode) &&
    (else_keyword_loc.nil? == other.else_keyword_loc.nil?) &&
    (statements === other.statements) &&
    (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
end
accept(visitor) click to toggle source

def accept: (Visitor visitor) -> void

# File lib/prism/node.rb, line 6049
def accept(visitor)
  visitor.visit_else_node(self)
end
child_nodes() click to toggle source

def child_nodes: () -> Array[nil | Node]

# File lib/prism/node.rb, line 6054
def child_nodes
  [statements]
end
Also aliased as: deconstruct
comment_targets() click to toggle source

def comment_targets: () -> Array[Node | Location]

# File lib/prism/node.rb, line 6066
def comment_targets
  [else_keyword_loc, *statements, *end_keyword_loc] #: Array[Prism::node | Location]
end
compact_child_nodes() click to toggle source

def compact_child_nodes: () -> Array

# File lib/prism/node.rb, line 6059
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << statements if statements
  compact
end
copy(node_id: self.node_id, location: self.location, flags: self.flags, else_keyword_loc: self.else_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc) click to toggle source

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?else_keyword_loc: Location, ?statements: StatementsNode?, ?end_keyword_loc: Location?) -> ElseNode

# File lib/prism/node.rb, line 6071
def copy(node_id: self.node_id, location: self.location, flags: self.flags, else_keyword_loc: self.else_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc)
  ElseNode.new(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc)
end
deconstruct()

def deconstruct: () -> Array[nil | Node]

Alias for: child_nodes
deconstruct_keys(keys) click to toggle source

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, else_keyword_loc: Location, statements: StatementsNode?, end_keyword_loc: Location? }

# File lib/prism/node.rb, line 6079
def deconstruct_keys(keys)
  { node_id: node_id, location: location, else_keyword_loc: else_keyword_loc, statements: statements, end_keyword_loc: end_keyword_loc }
end
else_keyword() click to toggle source

def else_keyword: () -> String

# File lib/prism/node.rb, line 6119
def else_keyword
  else_keyword_loc.slice
end
else_keyword_loc() click to toggle source

attr_reader else_keyword_loc: Location

# File lib/prism/node.rb, line 6084
def else_keyword_loc
  location = @else_keyword_loc
  return location if location.is_a?(Location)
  @else_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end
end_keyword() click to toggle source

def end_keyword: () -> String?

# File lib/prism/node.rb, line 6124
def end_keyword
  end_keyword_loc&.slice
end
end_keyword_loc() click to toggle source

attr_reader end_keyword_loc: Location?

# File lib/prism/node.rb, line 6100
def end_keyword_loc
  location = @end_keyword_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end
inspect() click to toggle source

def inspect -> String

# File lib/prism/node.rb, line 6129
def inspect
  InspectVisitor.compose(self)
end
save_else_keyword_loc(repository) click to toggle source

Save the else_keyword_loc location using the given saved source so that it can be retrieved later.

# File lib/prism/node.rb, line 6092
def save_else_keyword_loc(repository)
  repository.enter(node_id, :else_keyword_loc)
end
save_end_keyword_loc(repository) click to toggle source

Save the end_keyword_loc location using the given saved source so that it can be retrieved later.

# File lib/prism/node.rb, line 6114
def save_end_keyword_loc(repository)
  repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil?
end
type() click to toggle source

Return a symbol representation of this node type. See Node#type.

# File lib/prism/node.rb, line 6134
def type
  :else_node
end