class Prism::EnsureNode

Represents an ‘ensure` clause in a `begin` statement.

begin
  foo
ensure
^^^^^^
  bar
end

Attributes

statements[R]

attr_reader statements: StatementsNode?

Public Class Methods

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

Initialize a new EnsureNode node.

# File prism/node.rb, line 5790
def initialize(source, node_id, location, flags, ensure_keyword_loc, statements, end_keyword_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @ensure_keyword_loc = ensure_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 prism/node.rb, line 5873
def self.type
  :ensure_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 prism/node.rb, line 5879
def ===(other)
  other.is_a?(EnsureNode) &&
    (ensure_keyword_loc.nil? == other.ensure_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 prism/node.rb, line 5801
def accept(visitor)
  visitor.visit_ensure_node(self)
end
child_nodes() click to toggle source

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

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

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

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

def compact_child_nodes: () -> Array

# File prism/node.rb, line 5811
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, ensure_keyword_loc: self.ensure_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, ?ensure_keyword_loc: Location, ?statements: StatementsNode?, ?end_keyword_loc: Location) -> EnsureNode

# File prism/node.rb, line 5823
def copy(node_id: self.node_id, location: self.location, flags: self.flags, ensure_keyword_loc: self.ensure_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc)
  EnsureNode.new(source, node_id, location, flags, ensure_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, ensure_keyword_loc: Location, statements: StatementsNode?, end_keyword_loc: Location }

# File prism/node.rb, line 5831
def deconstruct_keys(keys)
  { node_id: node_id, location: location, ensure_keyword_loc: ensure_keyword_loc, statements: statements, end_keyword_loc: end_keyword_loc }
end
end_keyword() click to toggle source

def end_keyword: () -> String

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

attr_reader end_keyword_loc: Location

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

def ensure_keyword: () -> String

# File prism/node.rb, line 5853
def ensure_keyword
  ensure_keyword_loc.slice
end
ensure_keyword_loc() click to toggle source

attr_reader ensure_keyword_loc: Location

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

def inspect -> String

# File prism/node.rb, line 5863
def inspect
  InspectVisitor.compose(self)
end
type() click to toggle source

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

# File prism/node.rb, line 5868
def type
  :ensure_node
end