class SyntaxTree::HashKeyFormatter::Labels

Formats the keys of a hash literal using labels.

Constants

LABEL

Public Instance Methods

format_key(q, key) click to toggle source
# File lib/syntax_tree/node.rb, line 1733
def format_key(q, key)
  case key
  when Label
    q.format(key)
  when SymbolLiteral
    q.format(key.value)
    q.text(":")
  when DynaSymbol
    parts = key.parts

    if parts.length == 1 && (part = parts.first) &&
         part.is_a?(TStringContent) && part.value.match?(LABEL)
      q.format(part)
      q.text(":")
    else
      q.format(key)
      q.text(":")
    end
  end
end