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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ QWords
Returns a new instance of QWords.
7206 7207 7208 7209 7210 7211 |
# File 'lib/syntax_tree/node.rb', line 7206 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
7198 7199 7200 |
# File 'lib/syntax_tree/node.rb', line 7198 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7204 7205 7206 |
# File 'lib/syntax_tree/node.rb', line 7204 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ TStringContent ]
-
the elements of the array
7201 7202 7203 |
# File 'lib/syntax_tree/node.rb', line 7201 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
7213 7214 7215 |
# File 'lib/syntax_tree/node.rb', line 7213 def accept(visitor) visitor.visit_qwords(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7217 7218 7219 |
# File 'lib/syntax_tree/node.rb', line 7217 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
7223 7224 7225 7226 7227 7228 7229 7230 |
# File 'lib/syntax_tree/node.rb', line 7223 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 |
# File 'lib/syntax_tree/node.rb', line 7232 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 |