Class: SyntaxTree::Words
- Inherits:
-
Object
- Object
- SyntaxTree::Words
- Defined in:
- lib/syntax_tree.rb
Overview
Words represents a string literal array with 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[ Word ]
-
the elements of this array.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(elements:, location:, comments: []) ⇒ Words
constructor
A new instance of Words.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(elements:, location:, comments: []) ⇒ Words
Returns a new instance of Words.
12809 12810 12811 12812 12813 |
# File 'lib/syntax_tree.rb', line 12809 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
12807 12808 12809 |
# File 'lib/syntax_tree.rb', line 12807 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the elements of this array
12801 12802 12803 |
# File 'lib/syntax_tree.rb', line 12801 def elements @elements end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12804 12805 12806 |
# File 'lib/syntax_tree.rb', line 12804 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
12815 12816 12817 |
# File 'lib/syntax_tree.rb', line 12815 def child_nodes [] end |
#format(q) ⇒ Object
12819 12820 12821 12822 12823 12824 12825 12826 12827 12828 12829 |
# File 'lib/syntax_tree.rb', line 12819 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
12831 12832 12833 12834 12835 12836 12837 12838 12839 12840 |
# File 'lib/syntax_tree.rb', line 12831 def pretty_print(q) q.group(2, "(", ")") do q.text("words") q.breakable q.group(2, "(", ")") { q.seplist(elements) { |element| q.pp(element) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
12842 12843 12844 12845 12846 |
# File 'lib/syntax_tree.rb', line 12842 def to_json(*opts) { type: :words, elems: elements, loc: location, cmts: comments }.to_json( *opts ) end |