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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(assocs:, location:) ⇒ BareAssocHash
Returns a new instance of BareAssocHash.
1822
1823
1824
1825
1826
|
# File 'lib/syntax_tree/node.rb', line 1822
def initialize(assocs:, location:)
@assocs = assocs
@location = location
= []
end
|
Instance Attribute Details
#assocs ⇒ Object
- Array[ Assoc | AssocSplat ]
1817
1818
1819
|
# File 'lib/syntax_tree/node.rb', line 1817
def assocs
@assocs
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1820
1821
1822
|
# File 'lib/syntax_tree/node.rb', line 1820
def
end
|
Instance Method Details
#===(other) ⇒ Object
1857
1858
1859
|
# File 'lib/syntax_tree/node.rb', line 1857
def ===(other)
other.is_a?(BareAssocHash) && ArrayMatch.call(assocs, other.assocs)
end
|
#accept(visitor) ⇒ Object
1828
1829
1830
|
# File 'lib/syntax_tree/node.rb', line 1828
def accept(visitor)
visitor.visit_bare_assoc_hash(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
1832
1833
1834
|
# File 'lib/syntax_tree/node.rb', line 1832
def child_nodes
assocs
end
|
#copy(assocs: nil, location: nil) ⇒ Object
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
|
# File 'lib/syntax_tree/node.rb', line 1836
def copy(assocs: nil, location: nil)
node =
BareAssocHash.new(
assocs: assocs || self.assocs,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
1849
1850
1851
|
# File 'lib/syntax_tree/node.rb', line 1849
def deconstruct_keys(_keys)
{ assocs: assocs, location: location, comments: }
end
|
1853
1854
1855
|
# File 'lib/syntax_tree/node.rb', line 1853
def format(q)
q.seplist(assocs) { |assoc| q.format(assoc) }
end
|
1861
1862
1863
|
# File 'lib/syntax_tree/node.rb', line 1861
def format_key(q, key)
(@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key)
end
|