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, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ Backtick

Returns a new instance of Backtick.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1714
1715
1716
# File 'lib/syntax_tree/node.rb', line 1714

def comments
  @comments
end

#valueObject (readonly)

String

the backtick in the string



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

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



1751
1752
1753
# File 'lib/syntax_tree/node.rb', line 1751

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

#accept(visitor) ⇒ Object



1722
1723
1724
# File 'lib/syntax_tree/node.rb', line 1722

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

#child_nodesObject Also known as: deconstruct



1726
1727
1728
# File 'lib/syntax_tree/node.rb', line 1726

def child_nodes
  []
end

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



1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
# File 'lib/syntax_tree/node.rb', line 1730

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



1743
1744
1745
# File 'lib/syntax_tree/node.rb', line 1743

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

#format(q) ⇒ Object



1747
1748
1749
# File 'lib/syntax_tree/node.rb', line 1747

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