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.
7073 7074 7075 7076 7077 7078 |
# File 'lib/syntax_tree/node.rb', line 7073 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
7065 7066 7067 |
# File 'lib/syntax_tree/node.rb', line 7065 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7071 7072 7073 |
# File 'lib/syntax_tree/node.rb', line 7071 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ TStringContent ]
-
the elements of the array
7068 7069 7070 |
# File 'lib/syntax_tree/node.rb', line 7068 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
7080 7081 7082 |
# File 'lib/syntax_tree/node.rb', line 7080 def accept(visitor) visitor.visit_qsymbols(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7084 7085 7086 |
# File 'lib/syntax_tree/node.rb', line 7084 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
7090 7091 7092 7093 7094 7095 7096 7097 |
# File 'lib/syntax_tree/node.rb', line 7090 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 |
# File 'lib/syntax_tree/node.rb', line 7099 def format(q) opening, closing = "%i[", "]" 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 |