Skip to content

Instantly share code, notes, and snippets.

@jrasanen
Created February 23, 2018 19:00
Show Gist options
  • Save jrasanen/0681fcfd03c7329e7d7fd7b03133233e to your computer and use it in GitHub Desktop.
Save jrasanen/0681fcfd03c7329e7d7fd7b03133233e to your computer and use it in GitHub Desktop.
numbers = [50, 43, 73, 22]
data = numbers.map.with_index do |x, i|
return { "a": i, "b": x }
end
puts(data) // => {"a"=>0, "b"=>50}
numbers = [50, 43, 73, 22]
data = numbers.map.with_index{ |x, i|
{ "a" => i, "b" => x }
}
puts(data) // => [{"a"=>0, "b"=>50}, {"a"=>1, "b"=>43}, {"a"=>2, "b"=>73}, {"a"=>3, "b"=>22}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment