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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(beginning: nil, elements: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, elements:, location:) ⇒ QSymbols
constructor
A new instance of QSymbols.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(beginning:, elements:, location:) ⇒ QSymbols
Returns a new instance of QSymbols.
8682 8683 8684 8685 8686 8687 |
# File 'lib/syntax_tree/node.rb', line 8682 def initialize(beginning:, elements:, location:) @beginning = beginning @elements = elements @location = location @comments = [] end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- QSymbolsBeg
-
the token that opens this array literal
8674 8675 8676 |
# File 'lib/syntax_tree/node.rb', line 8674 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8680 8681 8682 |
# File 'lib/syntax_tree/node.rb', line 8680 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ TStringContent ]
-
the elements of the array
8677 8678 8679 |
# File 'lib/syntax_tree/node.rb', line 8677 def elements @elements end |
Instance Method Details
#===(other) ⇒ Object
8742 8743 8744 8745 |
# File 'lib/syntax_tree/node.rb', line 8742 def ===(other) other.is_a?(QSymbols) && beginning === other.beginning && ArrayMatch.call(elements, other.elements) end |
#accept(visitor) ⇒ Object
8689 8690 8691 |
# File 'lib/syntax_tree/node.rb', line 8689 def accept(visitor) visitor.visit_qsymbols(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8693 8694 8695 |
# File 'lib/syntax_tree/node.rb', line 8693 def child_nodes [] end |
#copy(beginning: nil, elements: nil, location: nil) ⇒ Object
8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 |
# File 'lib/syntax_tree/node.rb', line 8697 def copy(beginning: nil, elements: nil, location: nil) node = QSymbols.new( beginning: beginning || self.beginning, elements: elements || self.elements, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
8711 8712 8713 8714 8715 8716 8717 8718 |
# File 'lib/syntax_tree/node.rb', line 8711 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 |
# File 'lib/syntax_tree/node.rb', line 8720 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 |