Created
June 6, 2013 10:46
-
-
Save thatandyrose/5720702 to your computer and use it in GitHub Desktop.
Add some grammar helpers to your String!
This file contains hidden or 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
class String | |
def articleize | |
me = self.downcase | |
an_startswith = ['a','e','i','o','u'] | |
an_exceptions = ['unit'] #add more when you think of them! | |
if me.start_with?(*(an_startswith + an_exceptions)) | |
return "an #{self}" | |
else | |
return "a #{self}" | |
end | |
end | |
def apostrophize | |
if self.downcase.end_with?('s') | |
return "#{self}'" | |
else | |
return "#{self}'s" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment