class Prism::ElseNode

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

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

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 10558
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

Public Instance Methods

statements → StatementsNode | nil click to toggle source

Returns the statements attribute.

# File lib/prism/node.rb, line 10685
def statements
  @statements
end

Locations

↑ top

Public Instance Methods

else_keyword_loc → Location click to toggle source

Returns the Location represented by else_keyword_loc.

# File lib/prism/node.rb, line 10664
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_loc → Location | nil click to toggle source

Returns the Location represented by end_keyword_loc.

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

Node Interface

↑ top

Public Class Methods

type() click to toggle source

See Node.type.

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

Public Instance Methods

accept(visitor) click to toggle source

See Node.accept.

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

See Node.child_nodes.

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

See Node.comment_targets.

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

See Node.compact_child_nodes.

# File lib/prism/node.rb, line 10606
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  if (statements = self.statements); compact << statements; end
  compact
end
copy(**fields) → ElseNode click to toggle source

Creates a copy of self with the given fields, using self as the template.

# File lib/prism/node.rb, line 10625
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()
Alias for: child_nodes
each_child_node() { |statements;| ... } click to toggle source

See Node.each_child_node.

# File lib/prism/node.rb, line 10597
def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  if (statements = self.statements); yield statements; end
end
type() click to toggle source

See Node#type.

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

Repository

↑ top

Public Instance Methods

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 10675
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 10713
def save_end_keyword_loc(repository)
  repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil?
end

Slicing

↑ top

Public Instance Methods

else_keyword → String click to toggle source

Slice the location of else_keyword_loc from the source.

# File lib/prism/node.rb, line 10724
def else_keyword
  else_keyword_loc.slice
end
end_keyword → String | nil click to toggle source

Slice the location of end_keyword_loc from the source.

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