Class: SyntaxTree::HashLiteral
Overview
HashLiteral represents a hash literal.
{ key => value }
Instance Attribute Summary collapse
-
#assocs ⇒ Object
readonly
- Array[ AssocNew | AssocSplat ]
-
the optional contents of the hash.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#lbrace ⇒ Object
readonly
- LBrace
-
the left brace that opens this hash.
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(lbrace:, assocs:, location:, comments: []) ⇒ HashLiteral
constructor
A new instance of HashLiteral.
Methods inherited from Node
Constructor Details
#initialize(lbrace:, assocs:, location:, comments: []) ⇒ HashLiteral
Returns a new instance of HashLiteral.
4272 4273 4274 4275 4276 4277 |
# File 'lib/syntax_tree/node.rb', line 4272 def initialize(lbrace:, assocs:, location:, comments: []) @lbrace = lbrace @assocs = assocs @location = location @comments = comments end |
Instance Attribute Details
#assocs ⇒ Object (readonly)
- Array[ AssocNew | AssocSplat ]
-
the optional contents of the hash
4267 4268 4269 |
# File 'lib/syntax_tree/node.rb', line 4267 def assocs @assocs end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4270 4271 4272 |
# File 'lib/syntax_tree/node.rb', line 4270 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that opens this hash
4264 4265 4266 |
# File 'lib/syntax_tree/node.rb', line 4264 def lbrace @lbrace end |
Instance Method Details
#accept(visitor) ⇒ Object
4279 4280 4281 |
# File 'lib/syntax_tree/node.rb', line 4279 def accept(visitor) visitor.visit_hash(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4283 4284 4285 |
# File 'lib/syntax_tree/node.rb', line 4283 def child_nodes [lbrace] + assocs end |
#deconstruct_keys(keys) ⇒ Object
4289 4290 4291 |
# File 'lib/syntax_tree/node.rb', line 4289 def deconstruct_keys(keys) { lbrace: lbrace, assocs: assocs, location: location, comments: comments } end |
#format(q) ⇒ Object
4293 4294 4295 4296 4297 4298 4299 |
# File 'lib/syntax_tree/node.rb', line 4293 def format(q) if q.parent.is_a?(Assoc) format_contents(q) else q.group { format_contents(q) } end end |
#format_key(q, key) ⇒ Object
4301 4302 4303 |
# File 'lib/syntax_tree/node.rb', line 4301 def format_key(q, key) (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key) end |