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.



11566
11567
11568
11569
11570
# File 'lib/syntax_tree.rb', line 11566

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



11564
11565
11566
# File 'lib/syntax_tree.rb', line 11564

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11561
11562
11563
# File 'lib/syntax_tree.rb', line 11561

def location
  @location
end

#valueObject (readonly)

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

the value of the

symbol



11558
11559
11560
# File 'lib/syntax_tree.rb', line 11558

def value
  @value
end

Instance Method Details

#child_nodesObject



11572
11573
11574
# File 'lib/syntax_tree.rb', line 11572

def child_nodes
  [value]
end

#format(q) ⇒ Object



11576
11577
11578
11579
# File 'lib/syntax_tree.rb', line 11576

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

#pretty_print(q) ⇒ Object



11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
# File 'lib/syntax_tree.rb', line 11581

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



11592
11593
11594
11595
11596
11597
11598
11599
# File 'lib/syntax_tree.rb', line 11592

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