Problem
You want to exchange the values between two variables without using a temporary variable.
Solution
! a = 3; b = 4 ! a, b = b, a
Discussion
Ruby allows you to do multiple assignments within a single expression. It is called parallel assignment. If the left hand side (LHS) has more values than the right hand side (RHS), the extra LHS values are set to nil. If the RHS has more values than the LHS, the extra RHS values are simply ignored.
Contrast
Perl has this feature when the LHS is assigned to in a list context. A common example is:
sub f { my ($a, $b, $c) = @_; }
As a result, you can swap two variables without a temporary in perl as well.
Related
TODO: LIST_OF_RELATED_ITEMS
Status: In Progress