File tree Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -3001,16 +3001,25 @@ def format(q)
30013001 else
30023002 q . format ( message )
30033003
3004- if arguments . is_a? ( ArgParen ) && arguments . arguments . nil? &&
3005- !message . is_a? ( Const )
3006- # If you're using an explicit set of parentheses on something that
3007- # looks like a constant, then we need to match that in order to
3008- # maintain valid Ruby. For example, you could do something like Foo(),
3009- # on which we would need to keep the parentheses to make it look like
3010- # a method call.
3011- else
3012- q . format ( arguments )
3013- end
3004+ # Note that this explicitly leaves parentheses in place even if they are
3005+ # empty. There are two reasons we would need to do this. The first is if
3006+ # we're calling something that looks like a constant, as in:
3007+ #
3008+ # Foo()
3009+ #
3010+ # In this case if we remove the parentheses then this becomes a constant
3011+ # reference and not a method call. The second is if we're calling a
3012+ # method that is the same name as a local variable that is in scope, as
3013+ # in:
3014+ #
3015+ # foo = foo()
3016+ #
3017+ # In this case we have to keep the parentheses or else it treats this
3018+ # like assigning nil to the local variable. Note that we could attempt
3019+ # to be smarter about this by tracking the local variables that are in
3020+ # scope, but for now it's simpler and more efficient to just leave the
3021+ # parentheses in place.
3022+ q . format ( arguments ) if arguments
30143023 end
30153024 end
30163025
Original file line number Diff line number Diff line change 22foo(bar)
33%
44foo()
5- -
6- foo
75%
86foo(barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr)
97-
You can’t perform that action at this time.
0 commit comments