Class: SyntaxTree::BareAssocHash
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
-
#assocs ⇒ Object
readonly
[Array[ Assoc | AssocSplat ]].
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
- #format_key(q, key) ⇒ Object
-
#initialize(assocs:, location:, comments: []) ⇒ BareAssocHash
constructor
A new instance of BareAssocHash.
Methods inherited from Node
Constructor Details
#initialize(assocs:, location:, comments: []) ⇒ BareAssocHash
Returns a new instance of BareAssocHash.
1404 1405 1406 1407 1408 |
# File 'lib/syntax_tree/node.rb', line 1404 def initialize(assocs:, location:, comments: []) @assocs = assocs @location = location @comments = comments end |
Instance Attribute Details
#assocs ⇒ Object (readonly)
- Array[ Assoc | AssocSplat ]
1399 1400 1401 |
# File 'lib/syntax_tree/node.rb', line 1399 def assocs @assocs end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1402 1403 1404 |
# File 'lib/syntax_tree/node.rb', line 1402 def comments @comments end |
Instance Method Details
#accept(visitor) ⇒ Object
1410 1411 1412 |
# File 'lib/syntax_tree/node.rb', line 1410 def accept(visitor) visitor.(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1414 1415 1416 |
# File 'lib/syntax_tree/node.rb', line 1414 def child_nodes assocs end |
#deconstruct_keys(keys) ⇒ Object
1420 1421 1422 |
# File 'lib/syntax_tree/node.rb', line 1420 def deconstruct_keys(keys) { assocs: assocs, location: location, comments: comments } end |
#format(q) ⇒ Object
1424 1425 1426 |
# File 'lib/syntax_tree/node.rb', line 1424 def format(q) q.seplist(assocs) { |assoc| q.format(assoc) } end |
#format_key(q, key) ⇒ Object
1428 1429 1430 |
# File 'lib/syntax_tree/node.rb', line 1428 def format_key(q, key) (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key) end |