Class: AstBuilder::LiteralToken
- Inherits:
-
Object
- Object
- AstBuilder::LiteralToken
- Defined in:
- lib/ast_builder/literal_token.rb
Overview
Represents a literal token entity to avoid any quotation marks on inspect. Parser::AST will recursively call nodes, using ‘inspect` for anything that’s not a ‘Node` type, so we can cheat to get the macro language in here.
Instance Method Summary collapse
-
#initialize(string) ⇒ LiteralToken
constructor
A new instance of LiteralToken.
-
#inspect ⇒ String
Won’t show quotes around it, which we need for literal tokens.
-
#to_s ⇒ String
Converts to a string.
Constructor Details
#initialize(string) ⇒ LiteralToken
Returns a new instance of LiteralToken.
7 8 9 |
# File 'lib/ast_builder/literal_token.rb', line 7 def initialize(string) @string = string end |
Instance Method Details
#inspect ⇒ String
Won’t show quotes around it, which we need for literal tokens
23 24 25 |
# File 'lib/ast_builder/literal_token.rb', line 23 def inspect to_s end |
#to_s ⇒ String
Converts to a string. If we happen to have gotten some extra fun we make sure it’s a string representation instead of a node.
16 17 18 |
# File 'lib/ast_builder/literal_token.rb', line 16 def to_s @string.to_s end |