Class: SyntaxTree::Backtick

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

Overview

Backtick represents the use of the ‘ operator. It’s usually found being used for an XStringLiteral, but could also be found as the name of a method being defined.

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initialize(value:, location:) ⇒ Backtick

Returns a new instance of Backtick.



1681
1682
1683
1684
1685
# File 'lib/syntax_tree/node.rb', line 1681

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1679
1680
1681
# File 'lib/syntax_tree/node.rb', line 1679

def comments
  @comments
end

#valueObject (readonly)

String

the backtick in the string



1676
1677
1678
# File 'lib/syntax_tree/node.rb', line 1676

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



1716
1717
1718
# File 'lib/syntax_tree/node.rb', line 1716

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

#accept(visitor) ⇒ Object



1687
1688
1689
# File 'lib/syntax_tree/node.rb', line 1687

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

#child_nodesObject Also known as: deconstruct



1691
1692
1693
# File 'lib/syntax_tree/node.rb', line 1691

def child_nodes
  []
end

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



1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
# File 'lib/syntax_tree/node.rb', line 1695

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

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

#deconstruct_keys(_keys) ⇒ Object



1708
1709
1710
# File 'lib/syntax_tree/node.rb', line 1708

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

#format(q) ⇒ Object



1712
1713
1714
# File 'lib/syntax_tree/node.rb', line 1712

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