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`.
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
Returns a new instance of VarRefsFormatter.
867 868 869 |
# File 'lib/syntax_tree/node.rb', line 867 def initialize(contents) @contents = contents end |
Instance Attribute Details
#contents ⇒ Object (readonly)
- Args
-
the contents of the array
865 866 867 |
# File 'lib/syntax_tree/node.rb', line 865 def contents @contents end |
Instance Method Details
#format(q) ⇒ Object
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 |
# File 'lib/syntax_tree/node.rb', line 871 def format(q) q.group(0, "[", "]") do q.indent do q.breakable("") separator = -> do q.text(",") q.fill_breakable end q.seplist(contents.parts, separator) { |part| q.format(part) } q.if_break { q.text(",") } if q.trailing_comma? end q.breakable("") end end |