Open HertzDevil opened 2 years ago
IMHO this makes code look more cryptic. Just to gain fewer keystrokes at the cost of cryptic code should be avoided.
In what ways are these short blocks more cryptic than existing short blocks that don't have combined assignments (e.g. all .+=
replaced with .[]=
), other things being the same?
I'm skeptical about actually using these for stylistic reasons, but I think it makes sense to implement for completeness.
Actually, if we do this then we might as well support it for calls that aren't short blocks, for completeness:
foo.bar.+=(1) # same as `foo.bar += 1`
case [1]
when .[0].+=(1) # does not actually work, because methods cannot be chained here yet
end
The same restrictions apply to the receiver chains of these combined assignments.
I think certain short blocks that involve combined assignments should be accepted:
The above short blocks should be equivalent to:
They in turn are normalized like any other combined assignments:
This requires that the receiver of the combined assignment within the short block must be a call and a valid assignment target that can expand to a setter call. The following would be disallowed:
Also multiple assignments will most likely be invalid because the short block syntax is effectively left-associative: