Created
November 7, 2014 18:38
-
-
Save seejohnrun/5188a62fdf8ef77c6248 to your computer and use it in GitHub Desktop.
Do want
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
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