Class: SyntaxTree::Symbols
- Inherits:
-
Object
- Object
- SyntaxTree::Symbols
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, elements:, location:, comments: []) ⇒ Symbols
constructor
A new instance of Symbols.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ Symbols
Returns a new instance of Symbols.
11640 11641 11642 11643 11644 11645 |
# File 'lib/syntax_tree.rb', line 11640 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
11629 11630 11631 |
# File 'lib/syntax_tree.rb', line 11629 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11638 11639 11640 |
# File 'lib/syntax_tree.rb', line 11638 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the words in the symbol array literal
11632 11633 11634 |
# File 'lib/syntax_tree.rb', line 11632 def elements @elements end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11635 11636 11637 |
# File 'lib/syntax_tree.rb', line 11635 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
11647 11648 11649 |
# File 'lib/syntax_tree.rb', line 11647 def child_nodes [] end |
#format(q) ⇒ Object
11651 11652 11653 11654 11655 11656 11657 11658 11659 11660 11661 11662 11663 11664 11665 11666 11667 11668 |
# File 'lib/syntax_tree.rb', line 11651 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 |
#pretty_print(q) ⇒ Object
11670 11671 11672 11673 11674 11675 11676 11677 11678 11679 |
# File 'lib/syntax_tree.rb', line 11670 def pretty_print(q) q.group(2, "(", ")") do q.text("symbols") q.breakable q.group(2, "(", ")") { q.seplist(elements) { |element| q.pp(element) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
11681 11682 11683 11684 11685 11686 11687 11688 |
# File 'lib/syntax_tree.rb', line 11681 def to_json(*opts) { type: :symbols, elems: elements, loc: location, cmts: comments }.to_json(*opts) end |