Skip to content

Instantly share code, notes, and snippets.

@chebyte
Created November 28, 2011 18:28
Show Gist options
  • Save chebyte/1401413 to your computer and use it in GitHub Desktop.
Save chebyte/1401413 to your computer and use it in GitHub Desktop.
monkey patch for return duplicates elements from array
#monkey patch for duplicates
module Enumerable
def dups
inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
end
end
== Usage
[1, 2, 3, 3].dups
#[3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment