Class: SyntaxTree::ArrayLiteral::VarRefsFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::ArrayLiteral::VarRefsFormatter
- Defined in:
- lib/syntax_tree/node.rb
Overview
Formats an array that contains only a list of variable references. To make things simpler, if there are a bunch, we format them all using the “fill” algorithm as opposed to breaking them into a ton of lines. For example,
[foo, , baz]
instead of becoming:
[
foo,
,
baz
]
would instead become:
[
foo, ,
baz
]
provided the line length was hit between ‘bar` and `baz`.
Defined Under Namespace
Classes: Separator
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
- Args
-
the contents of the array.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(contents) ⇒ VarRefsFormatter
constructor
A new instance of VarRefsFormatter.
Constructor Details
#initialize(contents) ⇒ VarRefsFormatter
905 906 907 |
# File 'lib/syntax_tree/node.rb', line 905 def initialize(contents) @contents = contents end |
Instance Attribute Details
#contents ⇒ Object (readonly)
- Args
-
the contents of the array
903 904 905 |
# File 'lib/syntax_tree/node.rb', line 903 def contents @contents end |
Instance Method Details
#format(q) ⇒ Object
909 910 911 912 913 914 915 916 917 918 919 920 |
# File 'lib/syntax_tree/node.rb', line 909 def format(q) q.text("[") q.group do q.indent do q.breakable_empty q.seplist(contents.parts, Separator.new) { |part| q.format(part) } q.if_break { q.text(",") } if q.trailing_comma? end q.breakable_empty end q.text("]") end |