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
-
.new(array) ⇒ Token
constructor
Create a new token object with the given ripper-compatible array.
Instance Method Summary
-
#event
The type of the token.
-
#location
The location of the token in the source.
-
#state
The state of the lexer when this token was produced.
-
#value
The slice of the source that this token represents.
-
#==(other)
Internal use only
We want to pretend that this is just an Array.
- #method_missing(name) Internal use only
- #respond_to_missing?(name, include_private = false) ⇒ Boolean Internal use only
Constructor Details
.new(array) ⇒ Token
Create a new token object with the given ripper-compatible array.
# 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)
# File 'lib/prism/lex_compat.rb', line 237
def method_missing(name, ...) # :nodoc: @array.send(name, ...) end
Instance Method Details
#==(other)
We want to pretend that this is just an Array.
# File 'lib/prism/lex_compat.rb', line 229
def ==(other) # :nodoc: @array == other end
#event
The type of the token.
# File 'lib/prism/lex_compat.rb', line 214
def event @array[1] end
#location
The location of the token in the source.
# File 'lib/prism/lex_compat.rb', line 209
def location @array[0] end
#respond_to_missing?(name, include_private = false) ⇒ Boolean
# 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.
# File 'lib/prism/lex_compat.rb', line 224
def state @array[3] end
#value
The slice of the source that this token represents.
# File 'lib/prism/lex_compat.rb', line 219
def value @array[2] end