a = [ 'a' ]
b = [ 'b' ]
def c
return [ '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...
# desired result
#
a == [ 'a', 'c' ]
b == [ 'b', 'd' ]
Right now I often find myself writing:
t, tt = c
a += t
b += tt
but that's kind of ugly if you ask me.
Edit: Single element arrays seemed to have confused some people since several answers below just don't answer the question. I have made it more clear by letting each array have at least 2 elements.
Edit2: I filed a feature request with ruby core to implement compound assignments on destructured arrays.