🔍

No recent searches

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

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

Initialize a new `EnsureNode` node.

type ()
Source

    # File lib/prism/node.rb, line 7167
    def self.type
      :ensure_node
    end

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

### Public Instance Methods

=== (other)
Source

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

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 7076
    def accept(visitor)
      visitor.visit_ensure_node(self)
    end

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

child_nodes ()
Source

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

def `child_nodes`: () -> Array

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 7100
    def comment_targets
      [ensure_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 7093
    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, ensure_keyword_loc: self.ensure_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc)
Source

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

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

deconstruct ()

def deconstruct: () -> Array

Alias for: child_nodes
deconstruct_keys (keys)
Source

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

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

each_child_node () { |statements| ... }
Source

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

      yield statements if statements
    end

def `each_child_node`: () { (Prism::node) -> void } -> void | () -> Enumerator

end_keyword ()
Source

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

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

end_keyword_loc ()
Source

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

attr_reader `end_keyword_loc`: `Location`

ensure_keyword ()
Source

    # File lib/prism/node.rb, line 7147
    def ensure_keyword
      ensure_keyword_loc.slice
    end

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

ensure_keyword_loc ()
Source

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

attr_reader `ensure_keyword_loc`: `Location`

inspect ()
Source

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

def inspect -> `String`

save_end_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 7142
    def save_end_keyword_loc(repository)
      repository.enter(node_id, :end_keyword_loc)
    end

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

save_ensure_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 7126
    def save_ensure_keyword_loc(repository)
      repository.enter(node_id, :ensure_keyword_loc)
    end

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

type ()
Source

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

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