class Prism::ElseNode - Documentation for Ruby 3.4
Description: class Prism::ElseNode: Represents an `else` clause in a `case`, `if`, or `unless` statement.
Keywords: ruby,class,Prism::ElseNode

# 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)
Source

    # File lib/prism/node.rb, line 6326
    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

Initialize a new `ElseNode` node.

type ()
Source

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

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

### Public Instance Methods

=== (other)
Source

    # File lib/prism/node.rb, line 6433
    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

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

accept (visitor)
Source

    # File lib/prism/node.rb, line 6337
    def accept(visitor)
      visitor.visit_else_node(self)
    end

def accept: (`Visitor` visitor) -> void

child_nodes ()
Source

    # File lib/prism/node.rb, line 6342
    def child_nodes
      [statements]
    end

def `child_nodes`: () -> Array

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 6354
    def comment_targets
      [else_keyword_loc, *statements, *end_keyword_loc] #: Array[Prism::node | Location]
    end

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

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 6347
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      compact << statements if statements
      compact
    end

def `compact_child_nodes`: () -> Array

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)
Source

    # File lib/prism/node.rb, line 6359
    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

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

deconstruct ()

def deconstruct: () -> Array

Alias for: child_nodes
deconstruct_keys (keys)
Source

    # File lib/prism/node.rb, line 6367
    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

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

else_keyword ()
Source

    # File lib/prism/node.rb, line 6407
    def else_keyword
      else_keyword_loc.slice
    end

def `else_keyword`: () -> `String`

else_keyword_loc ()
Source

    # File lib/prism/node.rb, line 6372
    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

attr_reader `else_keyword_loc`: `Location`

end_keyword ()
Source

    # File lib/prism/node.rb, line 6412
    def end_keyword
      end_keyword_loc&.slice
    end

def `end_keyword`: () -> `String`?

end_keyword_loc ()
Source

    # File lib/prism/node.rb, line 6388
    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

attr_reader `end_keyword_loc`: `Location`?

inspect ()
Source

    # File lib/prism/node.rb, line 6417
    def inspect
      InspectVisitor.compose(self)
    end

def inspect -> `String`

save_else_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 6380
    def save_else_keyword_loc(repository)
      repository.enter(node_id, :else_keyword_loc)
    end

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

save_end_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 6402
    def save_end_keyword_loc(repository)
      repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil?
    end

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

type ()
Source

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

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