34,333
edits
Changes
→Ruby Assignment Operators
x /= y; # Assigns a value of 2 to variable x (the same as x = x / y)
</pre>
== Parallel Assignment ==
Ruby also supports the parallel assignment of variables. This enables multiple variables to be initialized with a single like of Ruby code. For example:
<pre>
a = 10
b = 20
c = 30
</pre>
may be more quickly declared using parallel assignment:
<pre>
a, b, c = 10, 20, 30
</pre>
Parallel assignment is also useful for swapping the values held in two variables:
<pre>
a, b = b, c
</pre>