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
- #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.
2209 2210 2211 2212 2213 |
# File 'lib/syntax_tree.rb', line 2209 def initialize(assocs:, location:, comments: []) @assocs = assocs @location = location @comments = comments end |
Instance Attribute Details
#assocs ⇒ Object (readonly)
- Array[ AssocNew | AssocSplat ]
2201 2202 2203 |
# File 'lib/syntax_tree.rb', line 2201 def assocs @assocs end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2207 2208 2209 |
# File 'lib/syntax_tree.rb', line 2207 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2204 2205 2206 |
# File 'lib/syntax_tree.rb', line 2204 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
2215 2216 2217 |
# File 'lib/syntax_tree.rb', line 2215 def child_nodes assocs end |
#format(q) ⇒ Object
2219 2220 2221 |
# File 'lib/syntax_tree.rb', line 2219 def format(q) q.seplist(assocs) { |assoc| q.format(assoc) } end |
#format_key(q, key) ⇒ Object
2223 2224 2225 |
# File 'lib/syntax_tree.rb', line 2223 def format_key(q, key) (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key) end |
#pretty_print(q) ⇒ Object
2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 |
# File 'lib/syntax_tree.rb', line 2227 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
2238 2239 2240 2241 2242 2243 2244 2245 |
# File 'lib/syntax_tree.rb', line 2238 def to_json(*opts) { type: :bare_assoc_hash, assocs: assocs, loc: location, cmts: comments }.to_json(*opts) end |