Skip to content

Instantly share code, notes, and snippets.

@codenamev
Created December 12, 2013 17:51
Show Gist options
  • Save codenamev/7932326 to your computer and use it in GitHub Desktop.
Save codenamev/7932326 to your computer and use it in GitHub Desktop.
Titleize a string with exceptions
# encoding: utf-8
class String
def titleize(options = {})
exclusions = options[:exclude]
return ActiveSupport::Inflector.titleize(self) unless exclusions.present?
self.underscore.humanize.gsub(/\b(?<!['’`])(?!#{exclusions.join('|')})[a-z]/) { $&.capitalize }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment