Skip to content

Instantly share code, notes, and snippets.

@dmerrick
Created May 17, 2016 00:00
Show Gist options
  • Select an option

  • Save dmerrick/f07ed68d93076aa131d8848d4b90362c to your computer and use it in GitHub Desktop.

Select an option

Save dmerrick/f07ed68d93076aa131d8848d4b90362c to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
input = {
foo: [ 1, 2],
bar: [ 3, 4]
}
num_args = input.values.first.size
output = []
num_args.times do |index|
new_hash = {}
input.each do |key, value|
new_hash[key] = value[index]
end
output << new_hash
end
puts output.inspect
#=> [{:foo=>1, :bar=>3}, {:foo=>2, :bar=>4}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment