Class: SyntaxTree::QSymbols
Overview
QSymbols represents a symbol literal array without interpolation.
i[one two three]
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- QSymbolsBeg
-
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: []) ⇒ QSymbols
constructor
A new instance of QSymbols.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ QSymbols
Returns a new instance of QSymbols.
7319 7320 7321 7322 7323 7324 |
# File 'lib/syntax_tree/node.rb', line 7319 def initialize(beginning:, elements:, location:, comments: []) @beginning = beginning @elements = elements @location = location @comments = comments end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- QSymbolsBeg
-
the token that opens this array literal
7311 7312 7313 |
# File 'lib/syntax_tree/node.rb', line 7311 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7317 7318 7319 |
# File 'lib/syntax_tree/node.rb', line 7317 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ TStringContent ]
-
the elements of the array
7314 7315 7316 |
# File 'lib/syntax_tree/node.rb', line 7314 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
7326 7327 7328 |
# File 'lib/syntax_tree/node.rb', line 7326 def accept(visitor) visitor.visit_qsymbols(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7330 7331 7332 |
# File 'lib/syntax_tree/node.rb', line 7330 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
7336 7337 7338 7339 7340 7341 7342 7343 |
# File 'lib/syntax_tree/node.rb', line 7336 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 |
# File 'lib/syntax_tree/node.rb', line 7345 def format(q) opening, closing = "%i[", "]" if elements.any? { |element| element.match?(/[\[\]]/) } opening = beginning.value closing = Quotes.matching(opening[2]) end q.text(opening) q.group do q.indent do q.breakable_empty q.seplist( elements, ArrayLiteral::BREAKABLE_SPACE_SEPARATOR ) { |element| q.format(element) } end q.breakable_empty end q.text(closing) end |