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
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ Words
Returns a new instance of Words.
9109 9110 9111 9112 9113 9114 |
# File 'lib/syntax_tree/node.rb', line 9109 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
9101 9102 9103 |
# File 'lib/syntax_tree/node.rb', line 9101 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9107 9108 9109 |
# File 'lib/syntax_tree/node.rb', line 9107 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the elements of this array
9104 9105 9106 |
# File 'lib/syntax_tree/node.rb', line 9104 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
9116 9117 9118 |
# File 'lib/syntax_tree/node.rb', line 9116 def accept(visitor) visitor.visit_words(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9120 9121 9122 |
# File 'lib/syntax_tree/node.rb', line 9120 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
9126 9127 9128 9129 9130 9131 9132 9133 |
# File 'lib/syntax_tree/node.rb', line 9126 def deconstruct_keys(keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 |
# File 'lib/syntax_tree/node.rb', line 9135 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 |