Skip to content

Instantly share code, notes, and snippets.

@jkarmel
Created May 12, 2015 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkarmel/a1153f9b4bfc87626a20 to your computer and use it in GitHub Desktop.
Save jkarmel/a1153f9b4bfc87626a20 to your computer and use it in GitHub Desktop.
frequencies
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