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.
11560 11561 11562 11563 11564 11565 |
# File 'lib/syntax_tree.rb', line 11560 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
11549 11550 11551 |
# File 'lib/syntax_tree.rb', line 11549 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11558 11559 11560 |
# File 'lib/syntax_tree.rb', line 11558 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the words in the symbol array literal
11552 11553 11554 |
# File 'lib/syntax_tree.rb', line 11552 def elements @elements end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11555 11556 11557 |
# File 'lib/syntax_tree.rb', line 11555 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
11567 11568 11569 |
# File 'lib/syntax_tree.rb', line 11567 def child_nodes [] end |
#format(q) ⇒ Object
11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 |
# File 'lib/syntax_tree.rb', line 11571 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
11590 11591 11592 11593 11594 11595 11596 11597 11598 11599 |
# File 'lib/syntax_tree.rb', line 11590 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
11601 11602 11603 11604 11605 11606 11607 11608 |
# File 'lib/syntax_tree.rb', line 11601 def to_json(*opts) { type: :symbols, elems: elements, loc: location, cmts: comments }.to_json(*opts) end |