File tree 2 files changed +30
-13
lines changed
2 files changed +30
-13
lines changed Original file line number Diff line number Diff line change @@ -2607,26 +2607,24 @@ def deconstruct_keys(keys)
2607
2607
def format ( q )
2608
2608
q . group do
2609
2609
q . format ( message )
2610
- q . text ( " " )
2611
-
2612
- if align? ( self )
2613
- q . nest ( message . value . length + 1 ) { q . format ( arguments ) }
2614
- else
2615
- q . format ( arguments )
2616
- end
2610
+ align ( q , self ) { q . format ( arguments ) }
2617
2611
end
2618
2612
end
2619
2613
2620
2614
private
2621
2615
2622
- def align? ( node )
2616
+ def align ( q , node , & block )
2623
2617
case node . arguments
2624
2618
in Args [ parts : [ Def | Defs | DefEndless ] ]
2625
- false
2619
+ q . text ( " " )
2620
+ yield
2621
+ in Args [ parts : [ IfOp ] ]
2622
+ yield
2626
2623
in Args [ parts : [ Command => command ] ]
2627
- align? ( command )
2624
+ align ( q , command , & block )
2628
2625
else
2629
- true
2626
+ q . text ( " " )
2627
+ q . nest ( message . value . length + 1 ) { yield }
2630
2628
end
2631
2629
end
2632
2630
end
@@ -2698,9 +2696,15 @@ def format(q)
2698
2696
q . format ( message )
2699
2697
end
2700
2698
2701
- if arguments
2699
+ case arguments
2700
+ in Args [ parts : [ IfOp ] ]
2701
+ q . if_flat { q . text ( " " ) }
2702
+ q . format ( arguments )
2703
+ in Args
2702
2704
q . text ( " " )
2703
2705
q . nest ( argument_alignment ( q , doc ) ) { q . format ( arguments ) }
2706
+ else
2707
+ # If there are no arguments, print nothing.
2704
2708
end
2705
2709
end
2706
2710
end
@@ -8460,7 +8464,7 @@ def format(q)
8460
8464
if parentheses
8461
8465
q . text ( ")" )
8462
8466
elsif ternary
8463
- q . if_break { } . if_flat { q . text ( ")" ) }
8467
+ q . if_flat { q . text ( ")" ) }
8464
8468
end
8465
8469
end
8466
8470
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