Actions
Feature #12593
closedAllow compound assignements to work when destructuring arrays
Status:
Rejected
Assignee:
-
Target version:
-
Description
a = [ 'a', 'b' ]
b = [ 'c', 'd' ]
def c
return [ 'A', 'B' ], [ 'C', 'D' ]
end
a, b += c # -> would be awesome, but gives syntax error
a, b = a + c.first, b + c.last # clunky and will call method twice...
# current realistic use:
t, tt = c
a += t
b += tt
# desired result
#
p a == [ 'a', 'c', 'A', 'B' ] #-> true
p b == [ 'b', 'd', 'C', 'D' ] #-> true
I would propose that as
a, b = [ c, d ] # is equivalent to:
a = c
b = d
a, b += [ c, d ] # would be equivalent to:
a += c
b += d
This not working surprised me. It could work with all compound assignment operators I think. Maybe even with some other operators.
Actions
Like0
Like0Like0Like0