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.
8667 8668 8669 8670 8671 8672 |
# File 'lib/syntax_tree/node.rb', line 8667 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
8659 8660 8661 |
# File 'lib/syntax_tree/node.rb', line 8659 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8665 8666 8667 |
# File 'lib/syntax_tree/node.rb', line 8665 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the words in the symbol array literal
8662 8663 8664 |
# File 'lib/syntax_tree/node.rb', line 8662 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
8674 8675 8676 |
# File 'lib/syntax_tree/node.rb', line 8674 def accept(visitor) visitor.visit_symbols(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8678 8679 8680 |
# File 'lib/syntax_tree/node.rb', line 8678 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
8684 8685 8686 8687 8688 8689 8690 8691 |
# File 'lib/syntax_tree/node.rb', line 8684 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 |
# File 'lib/syntax_tree/node.rb', line 8693 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 |