Class: PrettierPrint::IfBreak
- Inherits:
-
Object
- Object
- PrettierPrint::IfBreak
- Defined in:
- lib/prettier_print.rb
Overview
A node in the print tree that represents printing one thing if the surrounding group node is broken and another thing if the surrounding group node is flat.
Instance Attribute Summary collapse
-
#break_contents ⇒ Object
readonly
Returns the value of attribute break_contents.
-
#flat_contents ⇒ Object
readonly
Returns the value of attribute flat_contents.
Instance Method Summary collapse
-
#initialize(break_contents: [], flat_contents: []) ⇒ IfBreak
constructor
A new instance of IfBreak.
- #pretty_print(q) ⇒ Object
Constructor Details
#initialize(break_contents: [], flat_contents: []) ⇒ IfBreak
Returns a new instance of IfBreak.
179 180 181 182 |
# File 'lib/prettier_print.rb', line 179 def initialize(break_contents: [], flat_contents: []) @break_contents = break_contents @flat_contents = flat_contents end |
Instance Attribute Details
#break_contents ⇒ Object (readonly)
Returns the value of attribute break_contents.
177 178 179 |
# File 'lib/prettier_print.rb', line 177 def break_contents @break_contents end |
#flat_contents ⇒ Object (readonly)
Returns the value of attribute flat_contents.
177 178 179 |
# File 'lib/prettier_print.rb', line 177 def flat_contents @flat_contents end |
Instance Method Details
#pretty_print(q) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/prettier_print.rb', line 184 def pretty_print(q) q.group(2, "if-break(", ")") do q.breakable("") q.group(2, "[", "],") do q.seplist(break_contents) { |content| q.pp(content) } end q.breakable q.group(2, "[", "]") do q.seplist(flat_contents) { |content| q.pp(content) } end end end |