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



1945
1946
1947
1948
1949
# File 'lib/syntax_tree.rb', line 1945

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



1943
1944
1945
# File 'lib/syntax_tree.rb', line 1943

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1940
1941
1942
# File 'lib/syntax_tree.rb', line 1940

def location
  @location
end

#valueObject (readonly)

String

the backtick in the string



1937
1938
1939
# File 'lib/syntax_tree.rb', line 1937

def value
  @value
end

Instance Method Details

#child_nodesObject



1951
1952
1953
# File 'lib/syntax_tree.rb', line 1951

def child_nodes
  []
end

#format(q) ⇒ Object



1955
1956
1957
# File 'lib/syntax_tree.rb', line 1955

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

#pretty_print(q) ⇒ Object



1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
# File 'lib/syntax_tree.rb', line 1959

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



1970
1971
1972
1973
1974
# File 'lib/syntax_tree.rb', line 1970

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