From: shyouhei@... Date: 2016-07-19T01:08:38+00:00 Subject: [ruby-core:76403] [Ruby trunk Feature#12593] Allow compound assignements to work when destructuring arrays Issue #12593 has been updated by Shyouhei Urabe. The problem is, parallel assignment can go ultra complex. Its left hand and right hand side not necessarily are arrays, or not always come in same count. `a, b = 1, [2], "3", :'4'` is a valid ruby code; there seems no reason to forbid `a, b += 1, [2], "3", :'4'`, or even, `a, b += 1`. One could think of behaviours of such assignments, but I doubt if there are reasonable definitions for all pitfall-ish situations. ---------------------------------------- Feature #12593: Allow compound assignements to work when destructuring arrays https://bugs.ruby-lang.org/issues/12593#change-59645 * Author: Naja Melan * Status: Open * Priority: Normal * Assignee: ---------------------------------------- ~~~ ruby 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 ~~~ ruby 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. -- https://bugs.ruby-lang.org/ Unsubscribe: