Class: SyntaxTree::QWords

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

Overview

QWords represents a string literal array without interpolation.

%w[one two three]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of QWords.



9154
9155
9156
9157
9158
# File 'lib/syntax_tree.rb', line 9154

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



9152
9153
9154
# File 'lib/syntax_tree.rb', line 9152

def comments
  @comments
end

#elementsObject (readonly)

Array[ TStringContent ]

the elements of the array



9146
9147
9148
# File 'lib/syntax_tree.rb', line 9146

def elements
  @elements
end

#locationObject (readonly)

Location

the location of this node



9149
9150
9151
# File 'lib/syntax_tree.rb', line 9149

def location
  @location
end

Instance Method Details

#child_nodesObject



9160
9161
9162
# File 'lib/syntax_tree.rb', line 9160

def child_nodes
  []
end

#format(q) ⇒ Object



9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
# File 'lib/syntax_tree.rb', line 9164

def format(q)
  q.group(0, "%w[", "]") 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



9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
# File 'lib/syntax_tree.rb', line 9176

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

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

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

#to_json(*opts) ⇒ Object



9187
9188
9189
9190
9191
# File 'lib/syntax_tree.rb', line 9187

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