Skip to content

Instantly share code, notes, and snippets.

@jbrowning
Created November 1, 2013 16:41
Show Gist options
  • Save jbrowning/7268147 to your computer and use it in GitHub Desktop.
Save jbrowning/7268147 to your computer and use it in GitHub Desktop.
Demo of array/block parallel assignment
def parallel_assignment_test(array, &block)
block.call array
end
animals = ["pig", "cow", "dog"]
# One
parallel_assignment_test(animals) { |one, two, three|
puts "One: #{one}"
puts "-------"
}
# Two
parallel_assignment_test(animals) { |one, two|
puts "One: #{one}"
puts "Two: #{two}"
puts "-------"
}
# Three
parallel_assignment_test(animals) { |one, two, three|
puts "One: #{one}"
puts "Two: #{two}"
puts "Three: #{three}"
puts "-------"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment