class SyntaxTree::HashLiteral

HashLiteral represents a hash literal.

{ key => value }

Attributes

assocs[R]
Array[ Assoc | AssocSplat ]

the optional contents of the hash

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

lbrace[R]
LBrace

the left brace that opens this hash

Public Class Methods

new(lbrace:, assocs:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 5687
def initialize(lbrace:, assocs:, location:)
  @lbrace = lbrace
  @assocs = assocs
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 5728
def ===(other)
  other.is_a?(HashLiteral) && lbrace === other.lbrace &&
    ArrayMatch.call(assocs, other.assocs)
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 5694
def accept(visitor)
  visitor.visit_hash(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 5698
def child_nodes
  [lbrace].concat(assocs)
end
Also aliased as: deconstruct
copy(lbrace: nil, assocs: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 5702
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
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 5716
def deconstruct_keys(_keys)
  { lbrace: lbrace, assocs: assocs, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 5720
def format(q)
  if q.parent.is_a?(Assoc)
    format_contents(q)
  else
    q.group { format_contents(q) }
  end
end
format_key(q, key) click to toggle source
# File lib/syntax_tree/node.rb, line 5733
def format_key(q, key)
  (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key)
end