# Both single and multiple assignment is supported # Whole array x = ["a", "b", "c"] print "x = [1, 2, 3] gives: ", x, "\n" # just the first element x, = ["a", "b", "c"] print "x, = [1, 2, 3] gives: ", x, "\n" # multiple to n vars x, y, z = ["a", "b", "c"] print "x, y, z = [1, 2, 3] gives: ", x, ", ", y, ", ", z, "\n" # We can use star params with that. The starred param gets the remainder x, *y = ["a", "b", "c"] print "x, *y = [1, 2, 3] gives: ", x, ", ", y, "\n" # Leading from this, we can see that Ruby supports multiple assignment. # Multiple assignment works in parallel, such that we can swap arguments # like so: puts "x = #{x}; y = #{y}" x, y = y, x puts "x = #{x}; y = #{y}" # It's handy for any kind of initialization x, y = 13, 'etc' puts "x = #{x}; y = #{y}"