Class: SyntaxTree::Symbols
Overview
Symbols represents a symbol array literal with interpolation.
I[one two three]
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- SymbolsBeg
-
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 words in the symbol array literal.
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: []) ⇒ Symbols
constructor
A new instance of Symbols.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ Symbols
Returns a new instance of Symbols.
8653 8654 8655 8656 8657 8658 |
# File 'lib/syntax_tree/node.rb', line 8653 def initialize(beginning:, elements:, location:, comments: []) @beginning = beginning @elements = elements @location = location @comments = comments end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- SymbolsBeg
-
the token that opens this array literal
8645 8646 8647 |
# File 'lib/syntax_tree/node.rb', line 8645 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8651 8652 8653 |
# File 'lib/syntax_tree/node.rb', line 8651 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the words in the symbol array literal
8648 8649 8650 |
# File 'lib/syntax_tree/node.rb', line 8648 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
8660 8661 8662 |
# File 'lib/syntax_tree/node.rb', line 8660 def accept(visitor) visitor.visit_symbols(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8664 8665 8666 |
# File 'lib/syntax_tree/node.rb', line 8664 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
8670 8671 8672 8673 8674 8675 8676 8677 |
# File 'lib/syntax_tree/node.rb', line 8670 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 |
# File 'lib/syntax_tree/node.rb', line 8679 def format(q) opening, closing = "%I[", "]" 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 |