Skip to content

Instantly share code, notes, and snippets.

@ealdent
Created January 23, 2009 21:00
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 ealdent/51191 to your computer and use it in GitHub Desktop.
Save ealdent/51191 to your computer and use it in GitHub Desktop.
def smart_titleize
exclusion_word_pattern = /\b(and|as|at|but|by|for|from|in|into|of|on|onto|or|out|per|than|to|up|upon|via|with)\b/i
self.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
downcase.humanize.
gsub(/\b('?[a-z])/) { $1.capitalize }.
gsub(exclusion_word_pattern) { |i| i.downcase }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment