class Prism::Token - Documentation for Ruby 4.0
Description: class Prism::Token: This represents a token from the Ruby source.
Keywords: ruby,class,Prism::Token

🔍

No recent searches

# class Prism::Token

This represents a token from the Ruby source.

### Attributes

source [R]

The `Source` object that represents the source this token came from.

type [R]

The type of token that this token is.

value [R]

A byteslice of the source that this token represents.

### Public Class Methods

new (source, type, value, location)
Source

    # File lib/prism/parse_result.rb, line 816
    def initialize(source, type, value, location)
      @source = source
      @type = type
      @value = value
      @location = location
    end

Create a new token object with the given type, value, and location.

### Public Instance Methods

== (other)
Source

    # File lib/prism/parse_result.rb, line 851
    def ==(other)
      Token === other &&
        other.type == type &&
        other.value == value
    end

Returns true if the given other token is equal to this token.

deconstruct_keys (keys)
Source

    # File lib/prism/parse_result.rb, line 824
    def deconstruct_keys(keys)
      { type: type, value: value, location: location }
    end

Implement the hash pattern matching interface for `Token`.

deep_freeze ()
Source

    # File lib/prism/parse_result.rb, line 864
    def deep_freeze
      value.freeze
      location.freeze
      freeze
    end

Freeze this object and the objects it contains.

inspect ()
Source

    # File lib/prism/parse_result.rb, line 858
    def inspect
      location
      super
    end

Returns a string representation of this token.

Calls superclass method `Object#inspect`
location ()
Source

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

A `Location` object representing the location of this token in the source.

pretty_print (q)
Source

    # File lib/prism/parse_result.rb, line 836
    def pretty_print(q)
      q.group do
        q.text(type.to_s)
        self.location.pretty_print(q)
        q.text("(")
        q.nest(2) do
          q.breakable("")
          q.pp(value)
        end
        q.breakable("")
        q.text(")")
      end
    end

Implement the pretty print interface for `Token`.