Class: SyntaxTree::SymbolLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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.



9960
9961
9962
9963
9964
# File 'lib/syntax_tree/node.rb', line 9960

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



9958
9959
9960
# File 'lib/syntax_tree/node.rb', line 9958

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



9955
9956
9957
# File 'lib/syntax_tree/node.rb', line 9955

def location
  @location
end

#valueObject (readonly)

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

the value of the

symbol



9952
9953
9954
# File 'lib/syntax_tree/node.rb', line 9952

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



9966
9967
9968
# File 'lib/syntax_tree/node.rb', line 9966

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



9972
9973
9974
# File 'lib/syntax_tree/node.rb', line 9972

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



9976
9977
9978
9979
# File 'lib/syntax_tree/node.rb', line 9976

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

#pretty_print(q) ⇒ Object



9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
# File 'lib/syntax_tree/node.rb', line 9981

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



9992
9993
9994
9995
9996
9997
9998
9999
# File 'lib/syntax_tree/node.rb', line 9992

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