Skip to content

Instantly share code, notes, and snippets.

@Gaelan
Created April 26, 2016 03:44
Show Gist options
  • Save Gaelan/167af2b1e58d379064abb019e434694f to your computer and use it in GitHub Desktop.
Save Gaelan/167af2b1e58d379064abb019e434694f to your computer and use it in GitHub Desktop.
class Array
def by
inject Hash.new([]) { |obj, hash| hash[yield obj] << obj }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment