class Prism::InNode - Documentation for Ruby 4.1
Description: class Prism::InNode: Represents the use of the `in` keyword in a case statement.
Keywords: ruby,class,Prism::InNode

🔍

No recent searches

# class Prism::InNode

Represents the use of the `in` keyword in a case statement.

    case a; in b then c end
            ^^^^^^^^^^^

### Public Class Methods

new (source, node_id, location, flags, pattern, statements, in_loc, then_loc)
Source

    # File lib/prism/node.rb, line 15158
    def initialize(source, node_id, location, flags, pattern, statements, in_loc, then_loc)
      @source = source
      @node_id = node_id
      @location = location
      @flags = flags
      @pattern = pattern
      @statements = statements
      @in_loc = in_loc
      @then_loc = then_loc
    end

Initialize a new `InNode` node.

### Public Instance Methods

pattern → Node
Source

    # File lib/prism/node.rb, line 15266
    def pattern
      @pattern
    end

Returns the `pattern` attribute.

statements → StatementsNode | nil
Source

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

Returns the `statements` attribute.

## Locations

### Public Instance Methods

in_loc → Location
Source

    # File lib/prism/node.rb, line 15287
    def in_loc
      location = @in_loc
      return location if location.is_a?(Location)
      @in_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
    end

Returns the `Location` represented by `in_loc`.

then_loc → Location | nil
Source

    # File lib/prism/node.rb, line 15309
    def then_loc
      location = @then_loc
      case location
      when nil
        nil
      when Location
        location
      else
        @then_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
      end
    end

Returns the `Location` represented by `then_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 15249
    def self.type
      :in_node
    end

See `Node.type`.

### Public Instance Methods

accept (visitor)
Source

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

See `Node.accept`.

child_nodes ()
Source

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

See `Node.child_nodes`.

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 15218
    def comment_targets
      [pattern, *statements, in_loc, *then_loc] #: Array[Prism::node | Location]
    end

See `Node.comment_targets`.

compact_child_nodes ()
Source

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

See `Node.compact_child_nodes`.

copy(**fields) → InNode
Source

    # File lib/prism/node.rb, line 15228
    def copy(node_id: self.node_id, location: self.location, flags: self.flags, pattern: self.pattern, statements: self.statements, in_loc: self.in_loc, then_loc: self.then_loc)
      InNode.new(source, node_id, location, flags, pattern, statements, in_loc, then_loc)
    end

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

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

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

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

See `Node.each_child_node`.

type ()
Source

    # File lib/prism/node.rb, line 15242
    def type
      :in_node
    end

See `Node#type`.

## Repository

Methods related to `Relocation`.

### Public Instance Methods

save_in_loc (repository)
Source

    # File lib/prism/node.rb, line 15298
    def save_in_loc(repository)
      repository.enter(node_id, :in_loc)
    end

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

save_then_loc (repository)
Source

    # File lib/prism/node.rb, line 15326
    def save_then_loc(repository)
      repository.enter(node_id, :then_loc) unless @then_loc.nil?
    end

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

## Slicing

### Public Instance Methods

in → String
Source

    # File lib/prism/node.rb, line 15337
    def in
      in_loc.slice
    end

Slice the location of `in_loc` from the source.

then → String | nil
Source

    # File lib/prism/node.rb, line 15347
    def then
      then_loc&.slice
    end

Slice the location of `then_loc` from the source.