Skip to content

Instantly share code, notes, and snippets.

@mudge
Created July 29, 2008 10:37
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 mudge/3058 to your computer and use it in GitHub Desktop.
Save mudge/3058 to your computer and use it in GitHub Desktop.
A fast count method for Ruby 1.8 arrays.
class Array
def count(elem)
length - (self - [elem]).length
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment