Created
May 12, 2015 07:08
-
-
Save jkarmel/a1153f9b4bfc87626a20 to your computer and use it in GitHub Desktop.
frequencies
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
class Array | |
def frequencies(&block) | |
block ||= ->(x) {x} | |
Hash[group_by(&block).map {|k,v| [k, v.present? ? v.count : nil]} ] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment