Class: Nay::Token
- Inherits:
-
Object
- Object
- Nay::Token
- Defined in:
- lib/nay/token.rb
Overview
Describes the output of the Lexer.
Instance Attribute Summary collapse
-
#literal ⇒ Object
readonly
Returns the value of attribute literal.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(type, literal = nil) ⇒ Token
constructor
A new instance of Token.
- #to_s ⇒ Object
Constructor Details
#initialize(type, literal = nil) ⇒ Token
Returns a new instance of Token.
8 9 10 11 12 13 |
# File 'lib/nay/token.rb', line 8 def initialize(type, literal = nil) @type = type.to_sym @literal = literal freeze end |
Instance Attribute Details
#literal ⇒ Object (readonly)
Returns the value of attribute literal.
6 7 8 |
# File 'lib/nay/token.rb', line 6 def literal @literal end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/nay/token.rb', line 6 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
19 20 21 |
# File 'lib/nay/token.rb', line 19 def ==(other) other.type == type && other.literal == literal end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/nay/token.rb', line 15 def to_s "['#{type}', '#{literal}']" end |