Class: Prism::LexCompat::Token

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.

Direct Known Subclasses

IgnoreStateToken

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ Token

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



204
205
206
# 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) ⇒ Object

:nodoc:



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

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

Instance Method Details

#==(other) ⇒ Object

We want to pretend that this is just an Array.



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

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

#eventObject

The type of the token.



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

def event
  @array[1]
end

#locationObject

The location of the token in the source.



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

def location
  @array[0]
end

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

:nodoc:

Returns:

  • (Boolean)


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

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

#stateObject

The state of the lexer when this token was produced.



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

def state
  @array[3]
end

#valueObject

The slice of the source that this token represents.



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

def value
  @array[2]
end