123456789_123456789_123456789_123456789_123456789_

Class: Prism::LexCompat::Token

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: BasicObject
Defined in: lib/prism/lex_compat.rb

Overview

When we produce tokens, we produce the same arrays that Ripper does. However, we add a couple of convenience methods onto them to make them a little easier to work with. We delegate all other methods to the array.

Class Method Summary

Instance Method Summary

Constructor Details

.new(array) ⇒ Token

Create a new token object with the given ripper-compatible array.

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 204

def initialize(array)
  @array = array
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 237

def method_missing(name, ...) # :nodoc:
  @array.send(name, ...)
end

Instance Method Details

#==(other)

This method is for internal use only.

We want to pretend that this is just an Array.

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 229

def ==(other) # :nodoc:
  @array == other
end

#event

The type of the token.

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 214

def event
  @array[1]
end

#location

The location of the token in the source.

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 209

def location
  @array[0]
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

This method is for internal use only.
[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 233

def respond_to_missing?(name, include_private = false) # :nodoc:
  @array.respond_to?(name, include_private)
end

#state

The state of the lexer when this token was produced.

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 224

def state
  @array[3]
end

#value

The slice of the source that this token represents.

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 219

def value
  @array[2]
end