Skip to content

Instantly share code, notes, and snippets.

@h3h
Created April 16, 2010 22:33
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 h3h/369056 to your computer and use it in GitHub Desktop.
Save h3h/369056 to your computer and use it in GitHub Desktop.
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