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/
Instance Method Summary collapse
Instance Method Details
#format_key(q, key) ⇒ Object
1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 |
# File 'lib/syntax_tree/node.rb', line 1439 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 |