Class: SyntaxTree::HashKeyFormatter::Labels
- Inherits:
-
Object
- Object
- SyntaxTree::HashKeyFormatter::Labels
- Defined in:
- lib/syntax_tree/node.rb
Overview
Formats the keys of a hash literal using labels.
Constant Summary collapse
- LABEL =
/\A[A-Za-z_](\w*[\w!?])?\z/.freeze
Instance Method Summary collapse
Instance Method Details
#format_key(q, key) ⇒ Object
1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 |
# File 'lib/syntax_tree/node.rb', line 1718 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 |