Class: SyntaxTree::Words
Overview
Words represents a string literal array with interpolation.
%W[one two three]
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- WordsBeg
-
the token that opens this array literal.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#elements ⇒ Object
readonly
- Array[ Word ]
-
the elements of this 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: []) ⇒ Words
constructor
A new instance of Words.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ Words
10223 10224 10225 10226 10227 10228 |
# File 'lib/syntax_tree/node.rb', line 10223 def initialize(beginning:, elements:, location:, comments: []) @beginning = beginning @elements = elements @location = location @comments = comments end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- WordsBeg
-
the token that opens this array literal
10215 10216 10217 |
# File 'lib/syntax_tree/node.rb', line 10215 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10221 10222 10223 |
# File 'lib/syntax_tree/node.rb', line 10221 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the elements of this array
10218 10219 10220 |
# File 'lib/syntax_tree/node.rb', line 10218 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
10230 10231 10232 |
# File 'lib/syntax_tree/node.rb', line 10230 def accept(visitor) visitor.visit_words(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
10234 10235 10236 |
# File 'lib/syntax_tree/node.rb', line 10234 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
10240 10241 10242 10243 10244 10245 10246 10247 |
# File 'lib/syntax_tree/node.rb', line 10240 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 |
# File 'lib/syntax_tree/node.rb', line 10249 def format(q) opening, closing = "%W[", "]" 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 |