Class: SyntaxTree::QWords
Overview
QWords represents a string literal array without interpolation.
%w[one two three]
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- QWordsBeg
-
the token that opens this array literal.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#elements ⇒ Object
readonly
- Array[ TStringContent ]
-
the elements of the array.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, elements:, location:, comments: []) ⇒ QWords
constructor
A new instance of QWords.
Methods inherited from Node
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ QWords
6408 6409 6410 6411 6412 6413 |
# File 'lib/syntax_tree/node.rb', line 6408 def initialize(beginning:, elements:, location:, comments: []) @beginning = beginning @elements = elements @location = location @comments = comments end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- QWordsBeg
-
the token that opens this array literal
6400 6401 6402 |
# File 'lib/syntax_tree/node.rb', line 6400 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6406 6407 6408 |
# File 'lib/syntax_tree/node.rb', line 6406 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ TStringContent ]
-
the elements of the array
6403 6404 6405 |
# File 'lib/syntax_tree/node.rb', line 6403 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
6415 6416 6417 |
# File 'lib/syntax_tree/node.rb', line 6415 def accept(visitor) visitor.visit_qwords(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6419 6420 6421 |
# File 'lib/syntax_tree/node.rb', line 6419 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
6425 6426 6427 6428 6429 6430 6431 6432 |
# File 'lib/syntax_tree/node.rb', line 6425 def deconstruct_keys(keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 |
# File 'lib/syntax_tree/node.rb', line 6434 def format(q) opening, closing = "%w[", "]" if elements.any? { |element| element.match?(/[\[\]]/) } opening = beginning.value closing = Quotes.matching(opening[2]) end q.group(0, opening, closing) do q.indent do q.breakable("") q.seplist(elements, -> { q.breakable }) do |element| q.format(element) end end q.breakable("") end end |