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.
9673 9674 9675 9676 9677 9678 |
# File 'lib/syntax_tree/node.rb', line 9673 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
9665 9666 9667 |
# File 'lib/syntax_tree/node.rb', line 9665 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9671 9672 9673 |
# File 'lib/syntax_tree/node.rb', line 9671 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the elements of this array
9668 9669 9670 |
# File 'lib/syntax_tree/node.rb', line 9668 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
9680 9681 9682 |
# File 'lib/syntax_tree/node.rb', line 9680 def accept(visitor) visitor.visit_words(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9684 9685 9686 |
# File 'lib/syntax_tree/node.rb', line 9684 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
9690 9691 9692 9693 9694 9695 9696 9697 |
# File 'lib/syntax_tree/node.rb', line 9690 def deconstruct_keys(keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 |
# File 'lib/syntax_tree/node.rb', line 9699 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 |