Class: PrettyPrint::Group
- Inherits:
-
Object
- Object
- PrettyPrint::Group
- Defined in:
- lib/syntax_tree/prettyprint.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.
149 150 151 152 153 |
# File 'lib/syntax_tree/prettyprint.rb', line 149 def initialize(depth, contents: []) @depth = depth @contents = contents @break = false end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
147 148 149 |
# File 'lib/syntax_tree/prettyprint.rb', line 147 def contents @contents end |
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
147 148 149 |
# File 'lib/syntax_tree/prettyprint.rb', line 147 def depth @depth end |
Instance Method Details
#break ⇒ Object
155 156 157 |
# File 'lib/syntax_tree/prettyprint.rb', line 155 def break @break = true end |
#break? ⇒ Boolean
159 160 161 |
# File 'lib/syntax_tree/prettyprint.rb', line 159 def break? @break end |
#pretty_print(q) ⇒ Object
163 164 165 166 167 |
# File 'lib/syntax_tree/prettyprint.rb', line 163 def pretty_print(q) q.group(2, "group([", "])") do q.seplist(contents) { |content| q.pp(content) } end end |