Class: SyntaxTree::BareAssocHash
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::BareAssocHash
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
BareAssocHash represents a hash of contents being passed as a method argument (and therefore has omitted braces). It’s very similar to an AssocListFromArgs node.
method(key1: value1, key2: value2)
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(assocs:, location:, comments: []) ⇒ BareAssocHash
1518
1519
1520
1521
1522
|
# File 'lib/syntax_tree/node.rb', line 1518
def initialize(assocs:, location:, comments: [])
@assocs = assocs
@location = location
=
end
|
Instance Attribute Details
#assocs ⇒ Object
- Array[ Assoc | AssocSplat ]
1513
1514
1515
|
# File 'lib/syntax_tree/node.rb', line 1513
def assocs
@assocs
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1516
1517
1518
|
# File 'lib/syntax_tree/node.rb', line 1516
def
end
|
Instance Method Details
#accept(visitor) ⇒ Object
1524
1525
1526
|
# File 'lib/syntax_tree/node.rb', line 1524
def accept(visitor)
visitor.visit_bare_assoc_hash(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
1528
1529
1530
|
# File 'lib/syntax_tree/node.rb', line 1528
def child_nodes
assocs
end
|
#deconstruct_keys(_keys) ⇒ Object
1534
1535
1536
|
# File 'lib/syntax_tree/node.rb', line 1534
def deconstruct_keys(_keys)
{ assocs: assocs, location: location, comments: }
end
|
1538
1539
1540
|
# File 'lib/syntax_tree/node.rb', line 1538
def format(q)
q.seplist(assocs) { |assoc| q.format(assoc) }
end
|
1542
1543
1544
|
# File 'lib/syntax_tree/node.rb', line 1542
def format_key(q, key)
(@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key)
end
|