Skip to content

Instantly share code, notes, and snippets.

@seejohnrun
Created November 7, 2014 18:38
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 seejohnrun/5188a62fdf8ef77c6248 to your computer and use it in GitHub Desktop.
Save seejohnrun/5188a62fdf8ef77c6248 to your computer and use it in GitHub Desktop.
Do want
module Enumerable
def map_count
Hash.new(0).tap { |h| each { |e| h[yield e] += 1 } }
end
end
puts [1, 2, 3, 4, 5].map_count(&:odd?) # {true=>3, false=>2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment