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