Skip to content

Instantly share code, notes, and snippets.

@danielmorrison
Created June 21, 2012 00:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielmorrison/2963190 to your computer and use it in GitHub Desktop.
Save danielmorrison/2963190 to your computer and use it in GitHub Desktop.
There *is* an I in team!
# Inspired by http://www.neatorama.com/2012/06/13/there-is-an-i-in-team/
class String
alias_method :original_count, :count
def count(letter)
if self == 'team' && letter.downcase == 'i'
1
else
original_count(letter)
end
end
end
@danielmorrison
Copy link
Author

Written during a Ruby class I was teaching today. When the group saw the built in string function count:

"hello world".count('o')
# => 2

We decided to alter it to show the hidden i in team
there it is

"team".count('i')
# => 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment