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.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

#valueObject (readonly)

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

the value of the

symbol



10404
10405
10406
# File 'lib/syntax_tree/node.rb', line 10404

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



10445
10446
10447
# File 'lib/syntax_tree/node.rb', line 10445

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

#accept(visitor) ⇒ Object



10415
10416
10417
# File 'lib/syntax_tree/node.rb', line 10415

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

#child_nodesObject Also known as: deconstruct



10419
10420
10421
# File 'lib/syntax_tree/node.rb', line 10419

def child_nodes
  [value]
end

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



10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
# File 'lib/syntax_tree/node.rb', line 10423

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



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

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

#format(q) ⇒ Object



10440
10441
10442
10443
# File 'lib/syntax_tree/node.rb', line 10440

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