Class: AstBuilder::LiteralToken

Inherits:
Object
  • Object
show all
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

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

#inspectString

Won’t show quotes around it, which we need for literal tokens

Returns:

  • (String)


23
24
25
# File 'lib/ast_builder/literal_token.rb', line 23

def inspect
  to_s
end

#to_sString

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.

Returns:

  • (String)


16
17
18
# File 'lib/ast_builder/literal_token.rb', line 16

def to_s
  @string.to_s
end