class Prism::EnsureNode - Documentation for Ruby 4.1
Description: class Prism::EnsureNode: Represents an `ensure` clause in a `begin` statement.
Keywords: ruby,class,Prism::EnsureNode

🔍

No recent searches

# class Prism::EnsureNode

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

    begin
      foo
    ensure
    ^^^^^^
      bar
    end

### Public Class Methods

new (source, node_id, location, flags, ensure_keyword_loc, statements, end_keyword_loc)
Source

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

### Public Instance Methods

statements → StatementsNode | nil
Source

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

Returns the `statements` attribute.

## Locations

### Public Instance Methods

end_keyword_loc → Location
Source

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

Returns the `Location` represented by `end_keyword_loc`.

ensure_keyword_loc → Location
Source

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

Returns the `Location` represented by `ensure_keyword_loc`.

## Node Interface

These methods are present on all subclasses of `Node`. Read the node interface docs for more information.

### Public Class Methods

type ()
Source

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

See `Node.type`.

### Public Instance Methods

accept (visitor)
Source

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

See `Node.accept`.

child_nodes ()
Source

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

See `Node.child_nodes`.

Also aliased as: deconstruct
comment_targets ()
Source

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

See `Node.comment_targets`.

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 11172
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      if (statements = self.statements); compact << statements; end
      compact
    end

See `Node.compact_child_nodes`.

copy(**fields) → EnsureNode
Source

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

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

deconstruct ()
Alias for: child_nodes
each_child_node () { |statements| ... }
Source

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

      if (statements = self.statements); yield statements; end
    end

See `Node.each_child_node`.

type ()
Source

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

See `Node#type`.

## Repository

Methods related to `Relocation`.

### Public Instance Methods

save_end_keyword_loc (repository)
Source

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

## Slicing

### Public Instance Methods

end_keyword → String
Source

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

Slice the location of `end_keyword_loc` from the source.

ensure_keyword → String
Source

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

Slice the location of `ensure_keyword_loc` from the source.