Class: SyntaxTree::QSymbols

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

QSymbols represents a symbol literal array without interpolation.

%i[one two three]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elements:, location:, comments: []) ⇒ QSymbols

Returns a new instance of QSymbols.



9047
9048
9049
9050
9051
# File 'lib/syntax_tree.rb', line 9047

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9045
9046
9047
# File 'lib/syntax_tree.rb', line 9045

def comments
  @comments
end

#elementsObject (readonly)

Array[ TStringContent ]

the elements of the array



9039
9040
9041
# File 'lib/syntax_tree.rb', line 9039

def elements
  @elements
end

#locationObject (readonly)

Location

the location of this node



9042
9043
9044
# File 'lib/syntax_tree.rb', line 9042

def location
  @location
end

Instance Method Details

#child_nodesObject



9053
9054
9055
# File 'lib/syntax_tree.rb', line 9053

def child_nodes
  []
end

#format(q) ⇒ Object



9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
# File 'lib/syntax_tree.rb', line 9057

def format(q)
  q.group(0, "%i[", "]") do
    q.indent do
      q.breakable("")
      q.seplist(elements, -> { q.breakable }) do |element|
        q.format(element)
      end
    end
    q.breakable("")
  end
end

#pretty_print(q) ⇒ Object



9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
# File 'lib/syntax_tree.rb', line 9069

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

    q.breakable
    q.group(2, "(", ")") { q.seplist(elements) { |element| q.pp(element) } }

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

#to_json(*opts) ⇒ Object



9080
9081
9082
9083
9084
9085
9086
9087
# File 'lib/syntax_tree.rb', line 9080

def to_json(*opts)
  {
    type: :qsymbols,
    elems: elements,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end