Class: PrettierPrint::Group
- Inherits:
-
Object
- Object
- PrettierPrint::Group
- Defined in:
- lib/prettier_print.rb
Overview
A node in the print tree that represents a group of items which the printer should try to fit onto one line. This is the basic command to tell the printer when to break. Groups are usually nested, and the printer will try to fit everything on one line, but if it doesn’t fit it will break the outermost group first and try again. It will continue breaking groups until everything fits (or there are no more groups to break).
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
Instance Method Summary collapse
- #break ⇒ Object
- #break? ⇒ Boolean
-
#initialize(depth, contents: []) ⇒ Group
constructor
A new instance of Group.
- #pretty_print(q) ⇒ Object
Constructor Details
#initialize(depth, contents: []) ⇒ Group
Returns a new instance of Group.
152 153 154 155 156 |
# File 'lib/prettier_print.rb', line 152 def initialize(depth, contents: []) @depth = depth @contents = contents @break = false end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
150 151 152 |
# File 'lib/prettier_print.rb', line 150 def contents @contents end |
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
150 151 152 |
# File 'lib/prettier_print.rb', line 150 def depth @depth end |
Instance Method Details
#break ⇒ Object
158 159 160 |
# File 'lib/prettier_print.rb', line 158 def break @break = true end |
#break? ⇒ Boolean
162 163 164 |
# File 'lib/prettier_print.rb', line 162 def break? @break end |
#pretty_print(q) ⇒ Object
166 167 168 169 170 |
# File 'lib/prettier_print.rb', line 166 def pretty_print(q) q.group(2, break? ? "breakGroup([" : "group([", "])") do q.seplist(contents) { |content| q.pp(content) } end end |