Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created March 16, 2011 23:09
Show Gist options
  • Select an option

  • Save practicingruby/873522 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/873522 to your computer and use it in GitHub Desktop.
class Array
def group_by
hash = Hash.new { |h,k| h[k] = [] }
each { |i| hash[yield(i)] << i }
hash
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment