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
1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 |
# 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 |