class Prism::AliasGlobalVariableNode - Documentation for Ruby 4.1
Description: class Prism::AliasGlobalVariableNode: Represents the use of the `alias` keyword to alias a global variable.
Keywords: ruby,class,Prism::AliasGlobalVariableNode

🔍

No recent searches

# class Prism::AliasGlobalVariableNode

Represents the use of the `alias` keyword to alias a global variable.

    alias $foo $bar
    ^^^^^^^^^^^^^^^

### Public Class Methods

new (source, node_id, location, flags, new_name, old_name, keyword_loc)
Source

    # File lib/prism/node.rb, line 450
    def initialize(source, node_id, location, flags, new_name, old_name, keyword_loc)
      @source = source
      @node_id = node_id
      @location = location
      @flags = flags
      @new_name = new_name
      @old_name = old_name
      @keyword_loc = keyword_loc
    end

Initialize a new `AliasGlobalVariableNode` node.

### Public Instance Methods

new_name → GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode
Source

    # File lib/prism/node.rb, line 557
    def new_name
      @new_name
    end

Represents the new name of the global variable that can be used after aliasing.

    alias $foo $bar
          ^^^^

old_name → GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode
Source

    # File lib/prism/node.rb, line 570
    def old_name
      @old_name
    end

Represents the old name of the global variable that can be used before aliasing.

    alias $foo $bar
               ^^^^

## Locations

### Public Instance Methods

keyword_loc → Location
Source

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

The `Location` of the `alias` keyword.

    alias $foo $bar
    ^^^^^

## 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 537
    def self.type
      :alias_global_variable_node
    end

See `Node.type`.

### Public Instance Methods

accept (visitor)
Source

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

See `Node.accept`.

child_nodes ()
Source

    # File lib/prism/node.rb, line 481
    def child_nodes
      [new_name, old_name]
    end

See `Node.child_nodes`.

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 506
    def comment_targets
      [new_name, old_name, keyword_loc] #: Array[Prism::node | Location]
    end

See `Node.comment_targets`.

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 499
    def compact_child_nodes
      [new_name, old_name]
    end

See `Node.compact_child_nodes`.

copy(**fields) → AliasGlobalVariableNode
Source

    # File lib/prism/node.rb, line 516
    def copy(node_id: self.node_id, location: self.location, flags: self.flags, new_name: self.new_name, old_name: self.old_name, keyword_loc: self.keyword_loc)
      AliasGlobalVariableNode.new(source, node_id, location, flags, new_name, old_name, 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 () { |new_name| ... }
Source

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

      yield new_name
      yield old_name
    end

See `Node.each_child_node`.

type ()
Source

    # File lib/prism/node.rb, line 530
    def type
      :alias_global_variable_node
    end

See `Node#type`.

## Repository

Methods related to `Relocation`.

### Public Instance Methods

save_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 595
    def save_keyword_loc(repository)
      repository.enter(node_id, :keyword_loc)
    end

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

## Slicing

### Public Instance Methods

keyword → String
Source

    # File lib/prism/node.rb, line 607
    def keyword
      keyword_loc.slice
    end

Slice the location of `keyword_loc` from the source.