Skip to content

Instantly share code, notes, and snippets.

@thatandyrose
Created June 6, 2013 10:46
Show Gist options
  • Save thatandyrose/5720702 to your computer and use it in GitHub Desktop.
Save thatandyrose/5720702 to your computer and use it in GitHub Desktop.
Add some grammar helpers to your String!
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