Created
November 28, 2011 18:28
-
-
Save chebyte/1401413 to your computer and use it in GitHub Desktop.
monkey patch for return duplicates elements from array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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