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[ AssocNew | AssocSplat ]].
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #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.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(assocs:, location:, comments: []) ⇒ BareAssocHash
Returns a new instance of BareAssocHash.
1733 1734 1735 1736 1737 |
# File 'lib/syntax_tree/node.rb', line 1733 def initialize(assocs:, location:, comments: []) @assocs = assocs @location = location @comments = comments end |
Instance Attribute Details
#assocs ⇒ Object (readonly)
- Array[ AssocNew | AssocSplat ]
1725 1726 1727 |
# File 'lib/syntax_tree/node.rb', line 1725 def assocs @assocs end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1731 1732 1733 |
# File 'lib/syntax_tree/node.rb', line 1731 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
1728 1729 1730 |
# File 'lib/syntax_tree/node.rb', line 1728 def location @location end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
1739 1740 1741 |
# File 'lib/syntax_tree/node.rb', line 1739 def child_nodes assocs end |
#deconstruct_keys(keys) ⇒ Object
1745 1746 1747 |
# File 'lib/syntax_tree/node.rb', line 1745 def deconstruct_keys(keys) { assocs: assocs, location: location, comments: comments } end |
#format(q) ⇒ Object
1749 1750 1751 |
# File 'lib/syntax_tree/node.rb', line 1749 def format(q) q.seplist(assocs) { |assoc| q.format(assoc) } end |
#format_key(q, key) ⇒ Object
1753 1754 1755 |
# File 'lib/syntax_tree/node.rb', line 1753 def format_key(q, key) (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key) end |
#pretty_print(q) ⇒ Object
1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 |
# File 'lib/syntax_tree/node.rb', line 1757 def pretty_print(q) q.group(2, "(", ")") do q.text("bare_assoc_hash") q.breakable q.group(2, "(", ")") { q.seplist(assocs) { |assoc| q.pp(assoc) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
1768 1769 1770 1771 1772 1773 1774 1775 |
# File 'lib/syntax_tree/node.rb', line 1768 def to_json(*opts) { type: :bare_assoc_hash, assocs: assocs, loc: location, cmts: comments }.to_json(*opts) end |