Last active
August 29, 2015 13:59
-
-
Save stujo/10776838 to your computer and use it in GitHub Desktop.
Ruby : Parallel Assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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