Class: SyntaxTree::Symbols
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Symbols
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Symbols represents a symbol array literal with interpolation.
%I[one two three]
Instance Attribute Summary collapse
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(beginning:, elements:, location:) ⇒ Symbols
10464
10465
10466
10467
10468
10469
|
# File 'lib/syntax_tree/node.rb', line 10464
def initialize(beginning:, elements:, location:)
@beginning = beginning
@elements = elements
@location = location
@comments = []
end
|
Instance Attribute Details
#beginning ⇒ Object
- SymbolsBeg
-
the token that opens this array literal
10456
10457
10458
|
# File 'lib/syntax_tree/node.rb', line 10456
def beginning
@beginning
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10462
10463
10464
|
# File 'lib/syntax_tree/node.rb', line 10462
def
@comments
end
|
#elements ⇒ Object
- Array[ Word ]
-
the words in the symbol array literal
10459
10460
10461
|
# File 'lib/syntax_tree/node.rb', line 10459
def elements
@elements
end
|
Instance Method Details
#===(other) ⇒ Object
10520
10521
10522
10523
|
# File 'lib/syntax_tree/node.rb', line 10520
def ===(other)
other.is_a?(Symbols) && beginning === other.beginning &&
ArrayMatch.call(elements, other.elements)
end
|
#accept(visitor) ⇒ Object
10471
10472
10473
|
# File 'lib/syntax_tree/node.rb', line 10471
def accept(visitor)
visitor.visit_symbols(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
10475
10476
10477
|
# File 'lib/syntax_tree/node.rb', line 10475
def child_nodes
[]
end
|
#copy(beginning: nil, elements: nil, location: nil) ⇒ Object
10479
10480
10481
10482
10483
10484
10485
|
# File 'lib/syntax_tree/node.rb', line 10479
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
10489
10490
10491
10492
10493
10494
10495
10496
|
# File 'lib/syntax_tree/node.rb', line 10489
def deconstruct_keys(_keys)
{
beginning: beginning,
elements: elements,
location: location,
comments:
}
end
|
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
|
# File 'lib/syntax_tree/node.rb', line 10498
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
|