Class: SyntaxTree::ArrayLiteral::QWordsFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::ArrayLiteral::QWordsFormatter
- Defined in:
- lib/syntax_tree/node.rb
Overview
Formats an array of multiple simple string literals into the %w syntax.
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
- Args
-
the contents of the array.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(contents) ⇒ QWordsFormatter
constructor
A new instance of QWordsFormatter.
Constructor Details
#initialize(contents) ⇒ QWordsFormatter
Returns a new instance of QWordsFormatter.
1070 1071 1072 |
# File 'lib/syntax_tree/node.rb', line 1070 def initialize(contents) @contents = contents end |
Instance Attribute Details
#contents ⇒ Object (readonly)
- Args
-
the contents of the array
1068 1069 1070 |
# File 'lib/syntax_tree/node.rb', line 1068 def contents @contents end |
Instance Method Details
#format(q) ⇒ Object
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
# File 'lib/syntax_tree/node.rb', line 1074 def format(q) q.text("%w[") q.group do q.indent do q.breakable_empty q.seplist(contents.parts, BREAKABLE_SPACE_SEPARATOR) do |part| if part.is_a?(StringLiteral) q.format(part.parts.first) else q.text(part.value[1..]) end end end q.breakable_empty end q.text("]") end |