Class: SyntaxTree::BareAssocHash
- Inherits:
-
Object
- Object
- SyntaxTree::BareAssocHash
- Defined in:
- lib/syntax_tree.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
-
#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
- #format(q) ⇒ 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.
2086 2087 2088 2089 2090 |
# File 'lib/syntax_tree.rb', line 2086 def initialize(assocs:, location:, comments: []) @assocs = assocs @location = location @comments = comments end |
Instance Attribute Details
#assocs ⇒ Object (readonly)
- Array[ AssocNew | AssocSplat ]
2078 2079 2080 |
# File 'lib/syntax_tree.rb', line 2078 def assocs @assocs end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2084 2085 2086 |
# File 'lib/syntax_tree.rb', line 2084 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2081 2082 2083 |
# File 'lib/syntax_tree.rb', line 2081 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
2092 2093 2094 |
# File 'lib/syntax_tree.rb', line 2092 def child_nodes assocs end |
#format(q) ⇒ Object
2096 2097 2098 |
# File 'lib/syntax_tree.rb', line 2096 def format(q) q.format(HashFormatter.for(self)) end |
#pretty_print(q) ⇒ Object
2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 |
# File 'lib/syntax_tree.rb', line 2100 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
2111 2112 2113 2114 2115 2116 2117 2118 |
# File 'lib/syntax_tree.rb', line 2111 def to_json(*opts) { type: :bare_assoc_hash, assocs: assocs, loc: location, cmts: comments }.to_json(*opts) end |