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
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ Symbols
Returns a new instance of Symbols.
7840 7841 7842 7843 7844 7845 |
# File 'lib/syntax_tree/node.rb', line 7840 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
7832 7833 7834 |
# File 'lib/syntax_tree/node.rb', line 7832 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7838 7839 7840 |
# File 'lib/syntax_tree/node.rb', line 7838 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the words in the symbol array literal
7835 7836 7837 |
# File 'lib/syntax_tree/node.rb', line 7835 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
7847 7848 7849 |
# File 'lib/syntax_tree/node.rb', line 7847 def accept(visitor) visitor.visit_symbols(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7851 7852 7853 |
# File 'lib/syntax_tree/node.rb', line 7851 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
7857 7858 7859 7860 7861 7862 7863 7864 |
# File 'lib/syntax_tree/node.rb', line 7857 def deconstruct_keys(keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 |
# File 'lib/syntax_tree/node.rb', line 7866 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 |