Class: SyntaxTree::QWords
- Inherits:
-
Object
- Object
- SyntaxTree::QWords
- Defined in:
- lib/syntax_tree.rb
Overview
QWords represents a string literal array without interpolation.
%w[one two three]
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#elements ⇒ Object
readonly
- Array[ TStringContent ]
-
the elements of the array.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(elements:, location:, comments: []) ⇒ QWords
constructor
A new instance of QWords.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(elements:, location:, comments: []) ⇒ QWords
Returns a new instance of QWords.
9154 9155 9156 9157 9158 |
# File 'lib/syntax_tree.rb', line 9154 def initialize(elements:, location:, comments: []) @elements = elements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9152 9153 9154 |
# File 'lib/syntax_tree.rb', line 9152 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ TStringContent ]
-
the elements of the array
9146 9147 9148 |
# File 'lib/syntax_tree.rb', line 9146 def elements @elements end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
9149 9150 9151 |
# File 'lib/syntax_tree.rb', line 9149 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
9160 9161 9162 |
# File 'lib/syntax_tree.rb', line 9160 def child_nodes [] end |
#format(q) ⇒ Object
9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 |
# File 'lib/syntax_tree.rb', line 9164 def format(q) q.group(0, "%w[", "]") do q.indent do q.breakable("") q.seplist(elements, -> { q.breakable }) do |element| q.format(element) end end q.breakable("") end end |
#pretty_print(q) ⇒ Object
9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 |
# File 'lib/syntax_tree.rb', line 9176 def pretty_print(q) q.group(2, "(", ")") do q.text("qwords") q.breakable q.group(2, "(", ")") { q.seplist(elements) { |element| q.pp(element) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
9187 9188 9189 9190 9191 |
# File 'lib/syntax_tree.rb', line 9187 def to_json(*opts) { type: :qwords, elems: elements, loc: location, cmts: comments }.to_json( *opts ) end |