Single assignment
In the case of single assignment, Ruby evaluates the left-hand side before the right-hand side.
In the below example,
the last expression calls lists, then data , then []= on the result of lists.
lists = ['ruby', 'python', 'scala']
data = 'rust'
lists[1] = dataBefore
Multiple assignments didn’t work this way. Let’s checkout the below example.
lists[1], tag.priority = data, numBefore Ruby 3.1, the above expression would be evaluated in the following order:
datanumlists[]=called on the result ofliststagpriority=called on the result of thetag
After
Starting with Ruby 3.1, multiple assignments evaluation order has been made consistent with single assignment evaluation order.
lists[1], tag.priority = data, numFor the above expression, the left-hand side is evaluated before the right-hand side and the order is as below:
liststagdatanum[]=called on the result oflistspriority=called on the result of thetag
