Skip to content

Instantly share code, notes, and snippets.

@ridget
Last active August 29, 2015 14:04
Show Gist options
  • Save ridget/31df0669666adcf6091e to your computer and use it in GitHub Desktop.
Save ridget/31df0669666adcf6091e to your computer and use it in GitHub Desktop.
group by and map on values in group thanks @mattc
# works in ruby 1.9
count.group_by { |o| o.site.name }.inject({}) { |m, (k,v)| m[k] = v.map(&:user_id); m }
# works in ruby 2.0 and above
count.group_by { |o| o.site.name }.map{ |k,v| [k, v.map(&:user_id)]}.to_h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment