class SyntaxTree::HashLiteral
HashLiteral
represents a hash literal.
{ key => value }
Attributes
- Array[
Assoc
|AssocSplat
] -
the optional contents of the hash
LBrace
-
the left brace that opens this hash
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 5702 def initialize(lbrace:, assocs:, location:) @lbrace = lbrace @assocs = assocs @location = location @comments = [] end
Public Instance Methods
Source
# File lib/syntax_tree/node.rb, line 5743 def ===(other) other.is_a?(HashLiteral) && lbrace === other.lbrace && ArrayMatch.call(assocs, other.assocs) end
Source
# File lib/syntax_tree/node.rb, line 5709 def accept(visitor) visitor.visit_hash(self) end
Source
# File lib/syntax_tree/node.rb, line 5713 def child_nodes [lbrace].concat(assocs) end
Also aliased as: deconstruct
Source
# File lib/syntax_tree/node.rb, line 5717 def copy(lbrace: nil, assocs: nil, location: nil) node = HashLiteral.new( lbrace: lbrace || self.lbrace, assocs: assocs || self.assocs, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
Source
# File lib/syntax_tree/node.rb, line 5731 def deconstruct_keys(_keys) { lbrace: lbrace, assocs: assocs, location: location, comments: comments } end
Source
# File lib/syntax_tree/node.rb, line 5735 def format(q) if q.parent.is_a?(Assoc) format_contents(q) else q.group { format_contents(q) } end end
Source
# File lib/syntax_tree/node.rb, line 5748 def format_key(q, key) (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key) end