Class: SyntaxTree::Backtick

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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.



2085
2086
2087
2088
2089
# File 'lib/syntax_tree.rb', line 2085

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



2083
2084
2085
# File 'lib/syntax_tree.rb', line 2083

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



2080
2081
2082
# File 'lib/syntax_tree.rb', line 2080

def location
  @location
end

#valueObject (readonly)

String

the backtick in the string



2077
2078
2079
# File 'lib/syntax_tree.rb', line 2077

def value
  @value
end

Instance Method Details

#child_nodesObject



2091
2092
2093
# File 'lib/syntax_tree.rb', line 2091

def child_nodes
  []
end

#format(q) ⇒ Object



2095
2096
2097
# File 'lib/syntax_tree.rb', line 2095

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

#pretty_print(q) ⇒ Object



2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
# File 'lib/syntax_tree.rb', line 2099

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



2110
2111
2112
2113
2114
# File 'lib/syntax_tree.rb', line 2110

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