Class: SyntaxTree::SymBeg

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

Overview

SymBeg represents the beginning of a symbol literal.

:symbol

SymBeg is also used for dynamic symbols, as in:

:"symbol"

Finally, SymBeg is also used for symbols using the %s syntax, as in:

%s[symbol]

The value of this node is a string. In most cases (as in the first example above) it will contain just “:”. In the case of dynamic symbols it will contain “:‘” or “:"”. In the case of %s symbols, it will contain the start of the symbol including the %s and the delimiter.

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #format, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ SymBeg

Returns a new instance of SymBeg.



10490
10491
10492
10493
# File 'lib/syntax_tree/node.rb', line 10490

def initialize(value:, location:)
  @value = value
  @location = location
end

Instance Attribute Details

#valueObject (readonly)

String

the beginning of the symbol



10488
10489
10490
# File 'lib/syntax_tree/node.rb', line 10488

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



10516
10517
10518
# File 'lib/syntax_tree/node.rb', line 10516

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

#accept(visitor) ⇒ Object



10495
10496
10497
# File 'lib/syntax_tree/node.rb', line 10495

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

#child_nodesObject Also known as: deconstruct



10499
10500
10501
# File 'lib/syntax_tree/node.rb', line 10499

def child_nodes
  []
end

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



10503
10504
10505
10506
10507
10508
# File 'lib/syntax_tree/node.rb', line 10503

def copy(value: nil, location: nil)
  SymBeg.new(
    value: value || self.value,
    location: location || self.location
  )
end

#deconstruct_keys(_keys) ⇒ Object



10512
10513
10514
# File 'lib/syntax_tree/node.rb', line 10512

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