Created
December 12, 2013 17:51
-
-
Save codenamev/7932326 to your computer and use it in GitHub Desktop.
Titleize a string with exceptions
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
# 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