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

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ SymbolLiteral

Returns a new instance of SymbolLiteral.



10400
10401
10402
10403
10404
# File 'lib/syntax_tree/node.rb', line 10400

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10398
10399
10400
# File 'lib/syntax_tree/node.rb', line 10398

def comments
  @comments
end

#valueObject (readonly)

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

the value of the

symbol



10395
10396
10397
# File 'lib/syntax_tree/node.rb', line 10395

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



10436
10437
10438
# File 'lib/syntax_tree/node.rb', line 10436

def ===(other)
  other.is_a?(SymbolLiteral) && value === other.value
end

#accept(visitor) ⇒ Object



10406
10407
10408
# File 'lib/syntax_tree/node.rb', line 10406

def accept(visitor)
  visitor.visit_symbol_literal(self)
end

#child_nodesObject Also known as: deconstruct



10410
10411
10412
# File 'lib/syntax_tree/node.rb', line 10410

def child_nodes
  [value]
end

#copy(value: nil, location: nil) ⇒ Object



10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
# File 'lib/syntax_tree/node.rb', line 10414

def copy(value: nil, location: nil)
  node =
    SymbolLiteral.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



10427
10428
10429
# File 'lib/syntax_tree/node.rb', line 10427

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

#format(q) ⇒ Object



10431
10432
10433
10434
# File 'lib/syntax_tree/node.rb', line 10431

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