Skip to content

Instantly share code, notes, and snippets.

@h3h h3h/gist:369056
Created Apr 16, 2010

Embed
What would you like to do?
module Enumerable
def how_many_have?(method)
self.select {|x| x.send(method)}.count
end
alias_method :how_many_are?, :how_many_have?
end
# >> [1,2,3,4,5].how_many_are?(:even?)
# => 2
#
# >> BirthdayWish.all.how_many_have?(:custom_short_reason?)
# => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.