Skip to content

Instantly share code, notes, and snippets.

@stujo
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stujo/10776838 to your computer and use it in GitHub Desktop.
Save stujo/10776838 to your computer and use it in GitHub Desktop.
Ruby : Parallel Assignment
def parallel_assigns
# Parallel Assignment
puts "Parallel assign a and b"
a, b = 1, 2
puts "a is #{a}"
puts "b is #{b}"
puts "Initializing c and d"
c = 1
d = 5
puts "c is #{c}"
puts "d is #{d}"
# Swap Values
puts "Swapping c and d"
c, d = d, c
puts "c is #{c}"
puts "d is #{d}"
# += operator
puts "Initializing i"
i = 10
puts "i is #{i}"
puts "Parallel Assign with i+=1 each"
e, f, g = i+= 1, i+= 1, i+= 1
puts "i is #{i}"
puts "e is #{e}"
puts "f is #{f}"
puts "g is #{g}"
end
parallel_assigns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment