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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(assocs:, location:, comments: []) ⇒ BareAssocHash
Returns a new instance of BareAssocHash.
1480 1481 1482 1483 1484 |
# File 'lib/syntax_tree/node.rb', line 1480 def initialize(assocs:, location:, comments: []) @assocs = assocs @location = location @comments = comments end |
Instance Attribute Details
#assocs ⇒ Object (readonly)
[Array[ Assoc | AssocSplat ]]
1475 1476 1477 |
# File 'lib/syntax_tree/node.rb', line 1475 def assocs @assocs end |
#comments ⇒ Object (readonly)
[Array[ Comment | EmbDoc ]] the comments attached to this node
1478 1479 1480 |
# File 'lib/syntax_tree/node.rb', line 1478 def comments @comments end |
Instance Method Details
#accept(visitor) ⇒ Object
1486 1487 1488 |
# File 'lib/syntax_tree/node.rb', line 1486 def accept(visitor) visitor.(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1490 1491 1492 |
# File 'lib/syntax_tree/node.rb', line 1490 def child_nodes assocs end |
#deconstruct_keys(_keys) ⇒ Object
1496 1497 1498 |
# File 'lib/syntax_tree/node.rb', line 1496 def deconstruct_keys(_keys) { assocs: assocs, location: location, comments: comments } end |
#format(q) ⇒ Object
1500 1501 1502 |
# File 'lib/syntax_tree/node.rb', line 1500 def format(q) q.seplist(assocs) { |assoc| q.format(assoc) } end |
#format_key(q, key) ⇒ Object
1504 1505 1506 |
# File 'lib/syntax_tree/node.rb', line 1504 def format_key(q, key) (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key) end |