Collecting users' data as an array
You very rarely need to modify a variable from inside an each block.

Instead, check out all the methods available to you in Array and Enumerable.

Among them, there's #each_with_objects, which you can use like so:

a.each_with_object({}) do |(name, id), hash|
  hash[name] ||= []
  hash[name] &lt;&lt; id
end


which'll produce the same hash as your current code.

You could also do:

a.group_by(&amp;:first).map do |name, pairs|
  [name, pairs.map(&amp;:last)]
end


That returns an array of arrays, but you can turn that into a Hash with Hash[]. You may not need to, though. A lot of things treat an Array object with [key, value]-style elements the same as a Hash object. Depends on your needs.