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.



1670
1671
1672
1673
1674
# File 'lib/syntax_tree/node.rb', line 1670

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1668
1669
1670
# File 'lib/syntax_tree/node.rb', line 1668

def comments
  @comments
end

#valueObject (readonly)

String

the backtick in the string



1665
1666
1667
# File 'lib/syntax_tree/node.rb', line 1665

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



1705
1706
1707
# File 'lib/syntax_tree/node.rb', line 1705

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

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



1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
# File 'lib/syntax_tree/node.rb', line 1684

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



1697
1698
1699
# File 'lib/syntax_tree/node.rb', line 1697

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

#format(q) ⇒ Object



1701
1702
1703
# File 'lib/syntax_tree/node.rb', line 1701

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