Swapping array elements using parallel assignment
问题 Intrigued by this question, I have played a bit with parallel assignment with arrays and method calls. So here's an paradigmatic example, trying to swap two members in an array, by their value: deck = ['A', 'B', 'C'] #=> ["A", "B", "C"] deck[deck.index("A")], deck[deck.index("B")] = deck[deck.index("B")], deck[deck.index("A")] #=> ["B", "A"] deck #=> ["A", "B", "C"] The array hasn't changed. But if we change the order of arguments, it works: deck[deck.index("B")], deck[deck.index("A")] = deck