File tree Expand file tree Collapse file tree 2 files changed +30
-13
lines changed Expand file tree Collapse file tree 2 files changed +30
-13
lines changed Original file line number Diff line number Diff line change @@ -2614,26 +2614,24 @@ def deconstruct_keys(keys)
2614
2614
def format ( q )
2615
2615
q . group do
2616
2616
q . format ( message )
2617
- q . text ( " " )
2618
-
2619
- if align? ( self )
2620
- q . nest ( message . value . length + 1 ) { q . format ( arguments ) }
2621
- else
2622
- q . format ( arguments )
2623
- end
2617
+ align ( q , self ) { q . format ( arguments ) }
2624
2618
end
2625
2619
end
2626
2620
2627
2621
private
2628
2622
2629
- def align? ( node )
2623
+ def align ( q , node , & block )
2630
2624
case node . arguments
2631
2625
in Args [ parts : [ Def | Defs | DefEndless ] ]
2632
- false
2626
+ q . text ( " " )
2627
+ yield
2628
+ in Args [ parts : [ IfOp ] ]
2629
+ yield
2633
2630
in Args [ parts : [ Command => command ] ]
2634
- align? ( command )
2631
+ align ( q , command , & block )
2635
2632
else
2636
- true
2633
+ q . text ( " " )
2634
+ q . nest ( message . value . length + 1 ) { yield }
2637
2635
end
2638
2636
end
2639
2637
end
@@ -2705,9 +2703,15 @@ def format(q)
2705
2703
q . format ( message )
2706
2704
end
2707
2705
2708
- if arguments
2706
+ case arguments
2707
+ in Args [ parts : [ IfOp ] ]
2708
+ q . if_flat { q . text ( " " ) }
2709
+ q . format ( arguments )
2710
+ in Args
2709
2711
q . text ( " " )
2710
2712
q . nest ( argument_alignment ( q , doc ) ) { q . format ( arguments ) }
2713
+ else
2714
+ # If there are no arguments, print nothing.
2711
2715
end
2712
2716
end
2713
2717
end
@@ -8467,7 +8471,7 @@ def format(q)
8467
8471
if parentheses
8468
8472
q . text ( ")" )
8469
8473
elsif ternary
8470
- q . if_break { } . if_flat { q . text ( ")" ) }
8474
+ q . if_flat { q . text ( ")" ) }
8471
8475
end
8472
8476
end
8473
8477
end
Original file line number Diff line number Diff line change @@ -458,6 +458,10 @@ def if_break
458
458
IfBreakBuilder . new
459
459
end
460
460
461
+ # Also effectively unnecessary, but here for compatibility.
462
+ def if_flat
463
+ end
464
+
461
465
# A noop that immediately yields.
462
466
def indent
463
467
yield
@@ -1011,6 +1015,15 @@ def if_break
1011
1015
IfBreakBuilder . new ( self , doc )
1012
1016
end
1013
1017
1018
+ # This is similar to if_break in that it also inserts an IfBreak node into the
1019
+ # print tree, however it's starting from the flat contents, and cannot be used
1020
+ # to build the break contents.
1021
+ def if_flat
1022
+ doc = IfBreak . new
1023
+
1024
+ with_target ( doc . flat_contents ) { yield }
1025
+ end
1026
+
1014
1027
# Very similar to the #nest method, this indents the nested content by one
1015
1028
# level by inserting an Indent node into the print tree. The contents of the
1016
1029
# node are determined by the block.
You can’t perform that action at this time.
0 commit comments