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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(beginning: nil, elements: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, elements:, location:) ⇒ Symbols
constructor
A new instance of Symbols.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(beginning:, elements:, location:) ⇒ Symbols
Returns a new instance of Symbols.
10455 10456 10457 10458 10459 10460 |
# File 'lib/syntax_tree/node.rb', line 10455 def initialize(beginning:, elements:, location:) @beginning = beginning @elements = elements @location = location @comments = [] end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- SymbolsBeg
-
the token that opens this array literal
10447 10448 10449 |
# File 'lib/syntax_tree/node.rb', line 10447 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10453 10454 10455 |
# File 'lib/syntax_tree/node.rb', line 10453 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the words in the symbol array literal
10450 10451 10452 |
# File 'lib/syntax_tree/node.rb', line 10450 def elements @elements end |
Instance Method Details
#===(other) ⇒ Object
10511 10512 10513 10514 |
# File 'lib/syntax_tree/node.rb', line 10511 def ===(other) other.is_a?(Symbols) && beginning === other.beginning && ArrayMatch.call(elements, other.elements) end |
#accept(visitor) ⇒ Object
10462 10463 10464 |
# File 'lib/syntax_tree/node.rb', line 10462 def accept(visitor) visitor.visit_symbols(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
10466 10467 10468 |
# File 'lib/syntax_tree/node.rb', line 10466 def child_nodes [] end |
#copy(beginning: nil, elements: nil, location: nil) ⇒ Object
10470 10471 10472 10473 10474 10475 10476 |
# File 'lib/syntax_tree/node.rb', line 10470 def copy(beginning: nil, elements: nil, location: nil) Symbols.new( beginning: beginning || self.beginning, elements: elements || self.elements, location: location || self.location ) end |
#deconstruct_keys(_keys) ⇒ Object
10480 10481 10482 10483 10484 10485 10486 10487 |
# File 'lib/syntax_tree/node.rb', line 10480 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 |
# File 'lib/syntax_tree/node.rb', line 10489 def format(q) opening, closing = "%I[", "]" if elements.any? { |element| element.match?(/[\[\]]/) } opening = beginning.value closing = Quotes.matching(opening[2]) end q.text(opening) q.group do q.indent do q.breakable_empty q.seplist( elements, ArrayLiteral::BREAKABLE_SPACE_SEPARATOR ) { |element| q.format(element) } end q.breakable_empty end q.text(closing) end |