Class: SyntaxTree::SymbolLiteral

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

SymbolLiteral represents a symbol in the system with no interpolation (as opposed to a DynaSymbol which has interpolation).

:symbol

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ SymbolLiteral

Returns a new instance of SymbolLiteral.



11007
11008
11009
11010
11011
# File 'lib/syntax_tree.rb', line 11007

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11005
11006
11007
# File 'lib/syntax_tree.rb', line 11005

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11002
11003
11004
# File 'lib/syntax_tree.rb', line 11002

def location
  @location
end

#valueObject (readonly)

Backtick | Const | CVar | GVar | Ident | IVar | Kw | Op

the value of the

symbol



10999
11000
11001
# File 'lib/syntax_tree.rb', line 10999

def value
  @value
end

Instance Method Details

#child_nodesObject



11013
11014
11015
# File 'lib/syntax_tree.rb', line 11013

def child_nodes
  [value]
end

#format(q) ⇒ Object



11017
11018
11019
11020
# File 'lib/syntax_tree.rb', line 11017

def format(q)
  q.text(":")
  q.format(value)
end

#pretty_print(q) ⇒ Object



11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
# File 'lib/syntax_tree.rb', line 11022

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("symbol_literal")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



11033
11034
11035
11036
11037
11038
11039
11040
# File 'lib/syntax_tree.rb', line 11033

def to_json(*opts)
  {
    type: :symbol_literal,
    value: value,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end