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

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ Backtick

Returns a new instance of Backtick.



1616
1617
1618
1619
1620
# File 'lib/syntax_tree/node.rb', line 1616

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1614
1615
1616
# File 'lib/syntax_tree/node.rb', line 1614

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1611
1612
1613
# File 'lib/syntax_tree/node.rb', line 1611

def location
  @location
end

#valueObject (readonly)

String

the backtick in the string



1608
1609
1610
# File 'lib/syntax_tree/node.rb', line 1608

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



1622
1623
1624
# File 'lib/syntax_tree/node.rb', line 1622

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



1628
1629
1630
# File 'lib/syntax_tree/node.rb', line 1628

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

#format(q) ⇒ Object



1632
1633
1634
# File 'lib/syntax_tree/node.rb', line 1632

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

#pretty_print(q) ⇒ Object



1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
# File 'lib/syntax_tree/node.rb', line 1636

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("backtick")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



1647
1648
1649
1650
1651
# File 'lib/syntax_tree/node.rb', line 1647

def to_json(*opts)
  { type: :backtick, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end